Upcoming API change: POST /api/submit

https://www.reddit.com/r/redditdev/comments/ezz3td/upcoming_api_change_post_apisubmit/

created by kemitche on 06/02/2020 at 21:07 UTC

91 upvotes, 8 top-level comments (showing 8)

Hello devs!

On the redesign today, moderators are able to define a set of post requirements* for their subreddits. What this means for users is that during post creation, users will have their posts validated to make sure that they meet specific requirements for that subreddit.

We're planning on having these per-subreddit requirements enforced on all platforms in the near future. When we enable this feature, requests to POST /api/submit and POST /api/editusertext will fail with HTTP 400 errors if the submission doesn't meet the requirements set by the moderators of the subreddit.

You can opt into this behavior early to see how it’ll affect your apps and scripts by passing `validate_on_submit=True` into POST /api/submit[1] and POST /api/editusertext[2]. Note that the set of post requirements that a mod can set may change and expand beyond what's currently available, so make sure to account for that when considering how to show these errors to users! As a best practice, for any validation error that you don't explicitly handle in your app, you should display the error returned from the API next to the indicated field. (In the sample response below, for example, you’d want to show the error "You must have "test", "dog" or "cat" somewhere in your title" near the title field on your app’s post submission page.

1: https://www.reddit.com/dev/api#POST_api_submit

2: https://www.reddit.com/dev/api#POST_api_editusertext

Failed validation errors should look similar to existing validation errors** so we expect that most clients won't require changes if you're already showing those errors to your users.

Here's an example JSON response for a simple case of an invalid post:

{
  "json": {
    "errors": [
      ["SUBMIT_VALIDATION_TITLE_REQUIREMENT", "You must have \"test\", \"dog\" or \"cat\" somewhere in your title. ", "title"],
      ["SUBMIT_VALIDATION_FLAIR_REQUIRED", "Post must contain post flair. ", "flair"],
      ["SUBMIT_VALIDATION_MIN_LENGTH", "You must have at least 10 characters in your title. ", "title"]
    ]
  }
}

Additionally, if you’d like to pre-emptively validate a submission against a subreddit's set of requirements, you can fetch them ahead of time using the endpoint GET /api/v1/{subreddit}/post_requirements[3]. For example, you could use this to set the max length of your client's form field for the post title to match the maximum length allowed by the subreddit.

3: https://www.reddit.com/dev/api#GET_api_v1_%7Bsubreddit%7D_post_requirements

You should expect us to launch this within the next several months, but no sooner than 90 days from now. We'll post an update here at least 1 week ahead of flipping the switch.

Let us know if you encounter any issues or have any feedback about these endpoints!

* These include min/max title lengths, post flair requirements, word requirements for the title and body, and more! You can check these out at https://new.reddit.com/r/SUBREDDIT_YOU_MODERATE/about/settings

TL:DR; POST /api/submit and POST /api/editusertext endpoints will respond with 400s in additional cases starting in about 3 months. Devs should verify that their error handling/display code works well with the new errors.

Comments

Comment by geo1088 at 06/02/2020 at 21:24 UTC

13 upvotes, 1 direct replies

This looks great, thanks for the update!

Is there any list of all the possible requirements and associated error codes (e.g. `SUBMIT_VALIDATION_TITLE_REQUIREMENT`) for API consumers?

Comment by kungming2 at 06/02/2020 at 23:35 UTC

6 upvotes, 1 direct replies

I made u/AssistantBOT specifically to help make flairs mandatory for posting, so having it natively across versions of Reddit would be great, and I don't even mind my bot being somewhat sherlocked in a few months[1] because this should have been done by the site itself a long time ago.

1: https://www.howtogeek.com/297651/what-does-it-mean-when-a-company-sherlocks-an-app/

That being said, I *really* hope this applies to mobile web too! Right now OPs can't even *select* flairs after posting on mobile web, let alone choose one when submitting.

Comment by Watchful1 at 06/02/2020 at 21:20 UTC

7 upvotes, 1 direct replies

Thanks a bunch for posting here in advance, this looks like an amazing feature.

Will there be a way via the api to fetch post requirements ahead of time for a subreddit?

More of a moderator question rather than a dev question. If you're going to allow requiring a flair to post, will there be an option in the legacy post creation page to assign a flair? It looks like all the other requirements are currently possible to do on the legacy site, but there's no way to set a flair during post creation.

Comment by Blank-Cheque at 06/02/2020 at 22:17 UTC

4 upvotes, 0 direct replies

holy shit rejoice!

Comment by [deleted] at 10/02/2020 at 00:25 UTC

2 upvotes, 1 direct replies

Will there be an endpoint to modify the existing rules?

Comment by TotesMessenger at 27/02/2020 at 19:30 UTC*

1 upvotes, 0 direct replies

I'm a bot, *bleep*, *bloop*. Someone has linked to this thread from another place on reddit:

[/r/redreader] I just want to double check that the new post requirements API changes are on the radar.

[/r/relayforreddit] I just want to double check that the new post requirements API changes are on the radar.

[/r/slideforreddit] I just want to double check that the new post requirements API changes are on the radar.

 *^(If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads.) ^(Info[1] ^/ ^Contact[2])*

1: /r/TotesMessenger

2: /message/compose?to=/r/TotesMessenger

Comment by MalOuija at 03/06/2020 at 15:51 UTC

1 upvotes, 0 direct replies

ONI j your x

Comment by FreeSpeechWarrior at 06/02/2020 at 23:51 UTC

-7 upvotes, 1 direct replies

I can’t say I’m very happy about reddit engaging in Prior Restraint but at least this form of censorship will be marginally more transparent than what currently transpires in large communities here.