Get last n new / updated posts using API?

AI-generated summary

In a Dev category discussion titled “Get last n new / updated posts using API?”, Samir_Sabri asks for help retrieving the last n posts via API, noting issues with missing post URLs, inability to limit results to n posts, and excessive returned fields. blake clarifies that /latest.json returns topics, not individual posts — for posts, use /posts.json. URLs can be constructed from topic_id or post_id (e.g., https://meta.discourse.org/t/307427 or https://meta.discourse.org/p/1514266). The default page size is 30; reducing it requires specifying topic_ids (impractical without prior knowledge), while increasing it requires paginated requests (e.g., ?page=1). Field restriction isn’t supported by the API — filtering must be done client-side. Lastly, ?ascending=false is redundant since it’s the default. The discussion offers practical workarounds but confirms API limitations for granular control over post retrieval.

Hello

I tried to use APIs to get last n posts using

uri = URI('https://mydomain.com/forum/latest.json?ascending=false')

however, I noticed the following:

  • could not have the URL of each post
  • could not strict result to last n posts.
  • how to restrict returned fields ? ex: I am getting all details currently.

Any idea ?

Are you trying to get the last n posts or the last n topics?

/latest.json will give you the latest topics

/posts.json will give you the latest posts across all topics.

The URLs you can just construct from the results based off of the topic_id or post_id.

For example a valid url for this topic is: https://meta.discourse.org/t/307427 and for the post would be https://meta.discourse.org/p/1514266.

There isn’t a way to change the default page size of 30. If you really really want less than 30 you have pass in the specific topic ids:

https://meta.discourse.org/latest.json?topic_ids[]=307427

But you would have to know what those topic ids are beforehand so not really all that helpful usually. If you want more than 30 you will have to make multiple requests and pass in the page parm.

https://meta.discourse.org/latest.json?page=1

You can’t, you will have to filter them out from the results yourself.

This is the default, so you don’t have to specify ascending=false, you can just leave this off.