Manage Submissions for Posts

Learn how to manage submissions using JavaScript Reddit API Wrapper.

In this lesson, we'll learn the reading posts and approving posts method with snoowrap.

Read posts

The posts we submit using scripts often go into the spam inbox of the moderators. To read the submitted posts, we use the getSpam() method to get all the spam messages. In the following method, we approve the post without opening Reddit.

Request parameters

Here are some important parameters we'll use to call the method:

Parameter

Type

Category

Description

only

string

optional

This restricts the item's type that is sent back in the response.

Click "Run" to view the latest submission in the spam inbox.

Press + to interact
import snoowrap from "snoowrap";
const reddit = new snoowrap({
client_id: "{{CLIENT_ID}}",
client_secret: "{{CLIENT_SECRET}}",
refresh_token: "{{REFRESH_TOKEN}}",
username: "{{USERNAME}}",
user_agent: "testscript by u/{{USERNAME}}",
});
async function readPost() {
try {
const mod = await reddit.getSubreddit("{{SUBREDDIT_NAME}}").getModqueue();
const unmod = await reddit
.getSubreddit("{{SUBREDDIT_NAME}}")
.getUnmoderated();
const spam = await reddit.getSubreddit("{{SUBREDDIT_NAME}}").getSpam();
const inbox = mod.concat(spam, unmod);
if (!inbox.length) {
console.log("No post in the queue");
}
else {
console.log(inbox[0].title);
}
} catch (error) {
printError(error);
}
}
readPost();

Let's look into the code given in the widget above:

  • Lines 3–9: We initialize the snoowrap requester. The parameters are explained in the Parameters for Making a Snoowrap Requester lesson in the Appendix

  • Lines 12–18: We use the getSpam(), getModqueue, and getUnmoderated() methods to get the posts in the spam, mod queue, and unmoderated inbox.

  • Line 20: We add them to one array. Then, we iterate over the combined list.

Response fields

This request returns JSON objects whose key properties are explained in the Response fields for Reddit API lesson in the Appendix.

Approve a submitted post

Once we have an ID of the post that is yet to be approved, we can approve the post using the approve() method.

Request parameters

Here are some important parameters we'll use to call the method:

Parameter

Type

Category

Description

id

string

required

A string of characters is used to identify a post.

Click "Run" to approve a post that was moved to the spam inbox.

Press + to interact
import snoowrap from "snoowrap";
const reddit = new snoowrap({
client_id: "{{CLIENT_ID}}",
client_secret: "{{CLIENT_SECRET}}",
refresh_token: "{{REFRESH_TOKEN}}",
username: "{{USERNAME}}",
user_agent: "testscript by u/{{USERNAME}}",
});
async function approvePost() {
try {
const post = await reddit.getSubmission("{{POST_ID}}").approve();
printResponse(post);
} catch (error) {
printError(error);
}
}
approvePost();

Let's look into the code given in the widget above:

  • Line 14: We used the approve() method to approve the submission. The expected output should be the ID of the post.

Response fields

This snoowrap request returns a JSON object with the post ID when it gets processed successfully.