Topic API gets the wrong posts- consistently off by 5

/t/slug/123.json?post_number=10 gets the 5th post. /t/slug/123.json?post_number=50 gets the 45th post, etc. It’s consistently off by 5. If you want to get all the posts, you have to use pagination, and unless you account for this, you’ll have an incorrect list.

I can only guess this was done to include a few previous posts for context. If that’s the case, IMHO that should be done in the UI, not the API.

This endpoint promises to return information including the specified post, for example:

○ → curl -s 'https://meta.discourse.org/t/fkb-pro-social-theme/234323.json?post_number=40' | jq .post_stream.posts[].post_number
33
34
35
36
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

As a single-page application, Discourse uses its API efficiently to minimise work. It’s not reasonable to make one API call per post; that would massively balloon the amount of back and forth between client and server.

It’s trivial to select the post you expect from the result. Same as above, getting only post 40’s cooked content:

○ → curl -s 'https://meta.discourse.org/t/fkb-pro-social-theme/234323.json?post_number=40' | jq -r '.post_stream.posts[] | select(.post_number == 40) | .cooked'
<p>Hi Tiago,</p>
<p>Can you please clarify it a little bit? Some screenshots, your actual code and where is your advert appear would be very helpful. Thank you <img src="https://emoji.discourse-cdn.com/twitter/slightly_smiling_face.png?v=12" title=":slightly_smiling_face:" class="emoji" alt=":slightly_smiling_face:" loading="lazy" width="20" height="20"></p>

Or, if you absolutely want to return information about only the single post you are querying, you are free to make a Data Explorer query that does only that.

1 Like

ok, but where is that documented?

I’m not against pagination.

You can see API documentation here: https://docs.discourse.org/#tag/Topics/operation/getSpecificPostsFromTopic

1 Like