Calling POST on /posts.json returns null

I’m trying to create a new post using the API (Discourse 2.2.0). In the settings, approve post count is set to 3 and approve unless trust level is set to 1: basic user.

When posting valid data, the response is an HTTP 200, but the response is null.

If approve post count and approve unless trust level are default values, the API returns JSON for the response.

We use the response to map a discourse topic/post to a record within our system. Naturally, we can’t make this linkage if we don’t receive back an id in the response.

Is this what the API is supposed to do? Why not send back a response and a status letting the API’s client know that the post/topic is under review?

Are you 100% sure this is returning nothing?

When I posted this post I got:

And we are explicit about returning stuff here:

https://github.com/discourse/discourse/blob/84a10f8212ba4c5ea6e5923b6dba4d0f0e9c44c5/app/controllers/posts_controller.rb#L177-L183

There may be some edge case though if your post hits the queue, but I am pretty sure it should return a payload.

Can you try: How to reverse engineer the Discourse API

5 Likes