# API fetch most recent posts for a topic

**URL:** https://meta.discourse.org/t/api-fetch-most-recent-posts-for-a-topic/72421
**Category:** Development
**Tags:** rest-api
**Created:** [19 Ottobre 2017, 4:05pm UTC](https://meta.discourse.org/t/api-fetch-most-recent-posts-for-a-topic/72421 "2017-10-19T16:05:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Reid\_Van\_Melle](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@Reid\_Van\_Melle](https://meta.discourse.org/u/Reid_Van_Melle)
#### Post date: [19 Ottobre 2017, 4:05pm UTC](https://meta.discourse.org/t/api-fetch-most-recent-posts-for-a-topic/72421/1 "2017-10-19T16:05:32Z")

</div>

I’ve read all of the discussions about using the API to fetch all of the posts for a particular topic using the post\_ids from the stream. However, I cannot seem to find anything that would allow me to fetch the most recent set of posts for a topic (i.e. how the website works). Instead, I’m get the oldest 20 posts from the topic. I think the most common use case for the API would be fetching the most recent posts, and then paging page into time.

Also, are there any undocumented parameters for controlling the chunk\_size? I was also looking for this in the admin interface.

---

<div class="post-metadata">

### Author: ![Reid\_Van\_Melle](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@Reid\_Van\_Melle](https://meta.discourse.org/u/Reid_Van_Melle)
#### Post date: [19 Ottobre 2017, 4:37pm UTC](https://meta.discourse.org/t/api-fetch-most-recent-posts-for-a-topic/72421/2 "2017-10-19T16:37:23Z")

</div>

One potential strategy I see is to use `http://<server>/t/<topic_id>/posts.json?post_ids[]=0` to get the stream of IDs, and then implement my own paging system starting at the end of the post stream..

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [19 Ottobre 2017, 8:55pm UTC](https://meta.discourse.org/t/api-fetch-most-recent-posts-for-a-topic/72421/3 "2017-10-19T20:55:31Z")

</div>

If you want the latest posts, you can use `http://<server>/t/-/<topic-id>/last.json`

In the response, you’ll get the last 20 posts in `post_stream > posts` and the list of all the post ids in `post_stream > stream`.

That should be enough to do the pagination 😉

---

<div class="post-metadata">

### Author: ![Reid\_Van\_Melle](https://avatars.discourse-cdn.com/v4/letter/r/ee7513/32.png) [@Reid\_Van\_Melle](https://meta.discourse.org/u/Reid_Van_Melle)
#### Post date: [20 Ottobre 2017, 1:20am UTC](https://meta.discourse.org/t/api-fetch-most-recent-posts-for-a-topic/72421/7 "2017-10-20T01:20:22Z")

</div>

Man — exactly what I was looking for — I combed the API docs and postman ☹ Thanks much!

Any inside knowledge on a way to set the page size?

does that just redirect to `http://<server>/t/<slug>/<topic-id>/99999999.json` ?

and seems like `http://<server>/t/<topic-id>/99999999.json` without the slug also works just fine!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [30 Settembre 2023, 8:10pm UTC](https://meta.discourse.org/t/api-fetch-most-recent-posts-for-a-topic/72421/10 "2023-09-30T20:10:43Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
