Get last n new / updated posts using API?

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 ?

1 Like

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.

1 Like