# Retrieve latest posts by ID

**URL:** https://meta.discourse.org/t/retrieve-latest-posts-by-id/202159
**Category:** Support
**Created:** [August 30, 2021, 7:19pm UTC](https://meta.discourse.org/t/retrieve-latest-posts-by-id/202159 "2021-08-30T19:19:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![hkremer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hkremer/32/246287_2.png) [@hkremer](https://meta.discourse.org/u/hkremer)
#### Post date: [August 30, 2021, 7:19pm UTC](https://meta.discourse.org/t/retrieve-latest-posts-by-id/202159/1 "2021-08-30T19:19:55Z")

</div>

Hi there,

Is it possible to order posts in the api response?

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

Thank you!

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [August 30, 2021, 8:16pm UTC](https://meta.discourse.org/t/retrieve-latest-posts-by-id/202159/2 "2021-08-30T20:16:30Z")

</div>

Like this? [https://meta.discourse.org/latest.json?order=created](https://meta.discourse.org/latest.json?order=created)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [August 30, 2021, 8:21pm UTC](https://meta.discourse.org/t/retrieve-latest-posts-by-id/202159/3 "2021-08-30T20:21:29Z")

</div>

Also more specifically [https://meta.discourse.org/posts.json](https://meta.discourse.org/posts.json)

---

<div class="post-metadata">

### Author: ![hkremer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hkremer/32/246287_2.png) [@hkremer](https://meta.discourse.org/u/hkremer)
#### Post date: [August 31, 2021, 8:42pm UTC](https://meta.discourse.org/t/retrieve-latest-posts-by-id/202159/4 "2021-08-31T20:42:34Z")

</div>

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.](https://meta.discourse.org/t/latest-posts-api-pagination/88589/4) If we can’t order posts by ID then it becomes impossible.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [August 31, 2021, 8:46pm UTC](https://meta.discourse.org/t/retrieve-latest-posts-by-id/202159/5 "2021-08-31T20:46:39Z")

</div>

> [@hkremer](#):
>
> Rafael has the right base, but I don’t think you can order by created date (I hope I’m wrong?).

The default ordering is the created date AFAIK.

> [@hkremer](#):
>
> And if you could, I don’t believe IDs are assigned to posts based on when they are created.

They are.

> [@hkremer](#):
>
> Anecdotally in our Discourse instance, we are seeing many examples of IDs being assigned to posts outside of their chronological order.

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

> [@hkremer](#):
>
> This becomes an issue when you try to pull all posts using the method [discussed here.](https://meta.discourse.org/t/latest-posts-api-pagination/88589/4) If we can’t order posts by ID then it becomes impossible.

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](https://meta.discourse.org/t/data-explorer-plugin/32566) may be easier.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [August 31, 2021, 8:50pm UTC](https://meta.discourse.org/t/retrieve-latest-posts-by-id/202159/6 "2021-08-31T20:50:46Z")

</div>

> [@hkremer](#):
>
> Anecdotally in our Discourse instance, we are seeing many examples of IDs being assigned to posts outside of their chronological order.

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.

---

<div class="post-metadata">

### Author: ![hkremer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hkremer/32/246287_2.png) [@hkremer](https://meta.discourse.org/u/hkremer)
#### Post date: [September 13, 2021, 6:23pm UTC](https://meta.discourse.org/t/retrieve-latest-posts-by-id/202159/7 "2021-09-13T18:23:47Z")

</div>

Thank you! This is helpful context
