# How to get more posts from posts.json

**URL:** https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472
**Category:** Development
**Created:** [April 3, 2018, 3:33pm UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472 "2018-04-03T15:33:09Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![rmens](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@rmens](https://meta.discourse.org/u/rmens)
#### Post date: [April 3, 2018, 3:33pm UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472/1 "2018-04-03T15:33:09Z")

</div>

Hi guys,

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](https://meta.discourse.org/posts.json) but don’t get a consistent amount of posts back.

Is there any way to show the latest n posts. I tried [https://meta.discourse.org/posts.json?amount=50](https://meta.discourse.org/posts.json?amount=50) [https://meta.discourse.org/posts.json?limit=50](https://meta.discourse.org/posts.json?limit=50) and [https://meta.discourse.org/posts.json?posts=50](https://meta.discourse.org/posts.json?posts=50) but none of that is working.

Thanks!

---

<div class="post-metadata">

### Author: ![swarnava](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/swarnava/32/120151_2.png) [@swarnava](https://meta.discourse.org/u/swarnava)
#### Post date: [April 3, 2018, 5:03pm UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472/2 "2018-04-03T17:03:25Z")

</div>

There is something like that to fetch the latest posts: [https://meta.discourse.org/latest.json](https://meta.discourse.org/latest.json)

---

<div class="post-metadata">

### Author: ![Dalmiro\_Granas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dalmiro_granas/32/111811_2.png) [@Dalmiro\_Granas](https://meta.discourse.org/u/Dalmiro_Granas)
#### Post date: [September 24, 2018, 9:20pm UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472/3 "2018-09-24T21:20:06Z")

</div>

@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)”

---

<div class="post-metadata">

### Author: ![rmens](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@rmens](https://meta.discourse.org/u/rmens)
#### Post date: [September 25, 2018, 1:33pm UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472/4 "2018-09-25T13:33:17Z")

</div>

It’s also still not clear to me how to get the latest n posts, not topics.

---

<div class="post-metadata">

### Author: ![Dalmiro\_Granas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dalmiro_granas/32/111811_2.png) [@Dalmiro\_Granas](https://meta.discourse.org/u/Dalmiro_Granas)
#### Post date: [September 26, 2018, 4:53am UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472/5 "2018-09-26T04:53:09Z")

</div>

So the questions we have with @rmens are:

- How far back in time/amount of posts does `/posts.json` get you?
- Is this configurable in any way from the API call?

edit:

This thread looks promising: [Latest posts API pagination - #4 by blake](https://meta.discourse.org/t/latest-posts-api-pagination/88589/4)

I’ll post my findings tomorrow after testing this a bit more

---

<div class="post-metadata">

### Author: ![Dalmiro\_Granas](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dalmiro_granas/32/111811_2.png) [@Dalmiro\_Granas](https://meta.discourse.org/u/Dalmiro_Granas)
#### Post date: [September 26, 2018, 4:06pm UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472/6 "2018-09-26T16:06:04Z")

</div>

`/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:

1. GET `/posts.json` to get the last 50
2. GET `/posts.json?before=x` where x is the ID of the oldest post in the set of the previous GET call.
3. 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:

1. GET `/posts.json` to get the last 50.
2. 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.
3. Repeat until the GET call returns at least 1 post that was created more than 24hs ago.

Hope this helps anyone 🙂

---

<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: [September 26, 2018, 7:34pm UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472/7 "2018-09-26T19:34:52Z")

</div>

You got it, that’s how that endpoint is supposed to be used 🙂 (although you can just do +/-50 for pages after the 2nd)

And, if you run the script again, and know what number you stopped/started at…

---

<div class="post-metadata">

### Author: ![rmens](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@rmens](https://meta.discourse.org/u/rmens)
#### Post date: [October 1, 2018, 7:48am UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472/8 "2018-10-01T07:48:57Z")

</div>

This helped a lot. Thanks guys!

---

<div class="post-metadata">

### Author: ![John\_Lehmann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/john_lehmann/32/140084_2.png) [@John\_Lehmann](https://meta.discourse.org/u/John_Lehmann)
#### Post date: [April 22, 2021, 4:19pm UTC](https://meta.discourse.org/t/how-to-get-more-posts-from-posts-json/84472/9 "2021-04-22T16:19:47Z")

</div>

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?

> **[Discourse API Docs](https://docs.discourse.org/#tag/Posts)**
