Retrieve latest posts by ID

Hi there,

Is it possible to order posts in the api response?

I’m looking to retrieve posts, sorted by “id”.

Thank you!

Like this? https://meta.discourse.org/latest.json?order=created

1 Like

Also more specifically https://meta.discourse.org/posts.json

1 Like

Thanks both.

Richard, I think your request is for topics, not posts.

Rafael has the right base, but I don’t think you can order by created date (I hope I’m wrong?).

And if you could, I don’t believe IDs are assigned to posts based on when they are created.

Anecdotally in our Discourse instance, we are seeing many examples of IDs being assigned to posts outside of their chronological order.

This becomes an issue when you try to pull all posts using the method discussed here. If we can’t order posts by ID then it becomes impossible.

The default ordering is the created date AFAIK.

They are.

The gaps in the order are posts your user can’t see, most likely posts inside PMs.

If your goal is to extract ALL the posts, loading a full backup in a local PostgreSQL instance or even using our Data Explorer Plugin may be easier.

1 Like

Each Postgres leader grabs a bundle of, I believe, 32 auto increment IDs at once. If your database is large enough, then creations will alternate between bundles.

This also means that gaps will be created when you fail over a database.

Thank you! This is helpful context