I’m trying to integrate Discourse in another front-end and would like to show the latest posts on the frontpage. Im querying the API with for example https://meta.discourse.org/posts.json but don’t get a consistent amount of posts back.
@swarnava what is the difference between /lastest.json and /posts.json?
Edit after actually testing instead of just asking :
/latest.json returns the latest Topics
/posts.json returns the latest Posts
Is there a way to filter any of those by date? I’m also integrating Discourse with another tool, and I need to do “Give me all posts since (Now -7 days)”
/posts.json?before=X returns the first 50 posts with an ID lower than X. So if you want the get the lastest 75 posts for example, you can do:
GET /posts.json to get the last 50
GET /posts.json?before=x where x is the ID of the oldest post in the set of the previous GET call.
Get the first 25 posts of this last GET set and you’ll have the 75 you wanted.
In my case I needed all the posts from the last 24hs, so my code looks like:
GET /posts.json to get the last 50.
If the oldest post in the set returned by the previous GET was created between the last 24hs, I do GET /posts.json?before=x where x is the ID of the oldest post in the set of the previous GET call.
Repeat until the GET call returns at least 1 post that was created more than 24hs ago.
I have been relying on the before= parameter, however after noticing my code running in an infinite loop, I see that the API docs no longer include this parameter.
Is there another way to accomplish this now – how can we get more than the last 200 posts?