500 or 400 when updating the content of a post using the API

AI-generated summary

jviotti encountered issues updating a post via the Discourse REST API, receiving a 400 error for missing post param and a 500 error when using post in the body. After realizing they were using a topic ID instead of a post ID, the problem persisted with post 34816. Eventually, jviotti found that sending raw (not post) in the request body resolved the issue, suggesting the API docs could be clearer. pfaffman responded with encouragement and shared a helpful resource for reverse-engineering the API: How to Reverse-Engineer the Discourse API. The issue was not related to content or spam, but rather a mismatch between the API documentation and actual expected parameters.

I’m trying to update the content of a post using the API. The docs at Discourse API Docs mention that I should use PUT /posts/:id.json sending post[raw] as a body.

This results in 400 along with:

errors: [ 'param is missing or the value is empty: post' ]

The error is complaining about a param called post, but replacing post[raw] with post in my HTTP request results in a 500 Internal Server Error response.

The post content was just Edited comment, so I don’t think it’s anything related to the content.

Am I missing something? Are the API docs out of date?

I’m running a cloud instance at https://forums.balena.io. Not sure what the Discourse version is.

I just realised I was passing a topic id instead of a post id to the API, but the problem still persists. I’m trying to update post 34816, assuming you have access to the cloud instance:

PUT https://forums.balena.io/posts/34816.json

With body:

{
    "post": "Edited comment"
}

And that still results in 500.

Why is my post being flagged as spam? Is this not the right place to submit bugs?

Turns out it works fine if I pass raw instead of post in the request body. The docs could probably be clearer about that :slight_smile:

Glad you got it figured out! I’ve got a bunch of topics that are me taking to myself.

Mostly these are the docs, and they are continually updated: Reverse engineer the Discourse API :wink:

I generally forget that there are any docs besides just seeing how it works in the browser development tools.