# Api to fetch topic by page

**URL:** https://meta.discourse.org/t/api-to-fetch-topic-by-page/63342
**Category:** Development
**Tags:** rest-api
**Created:** [2017年五月25日 08:51 UTC](https://meta.discourse.org/t/api-to-fetch-topic-by-page/63342 "2017-05-25T08:51:41Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![gchiu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gchiu/32/95856_2.png) [@gchiu](https://meta.discourse.org/u/gchiu)
#### Post date: [2017年五月25日 08:51 UTC](https://meta.discourse.org/t/api-to-fetch-topic-by-page/63342/1 "2017-05-25T08:51:41Z")

</div>

I can see there is an api to [retrieve a topic](http://docs.discourse.org/#tag/Topics%2Fpaths%2F~1t~1%7Bid%7D.json%2Fget), and there is a chunk\_size of 20 I see in the response.

How do I get the next page?

> ```
> highest_post_number 33
> deleted_by _
> actions_summary [
> make map! [
> id 4
> count 0
> hidden false
> can_act false
> ]
> make map! [
> id 7
> count 0
> hidden false
> can_act false
> ]
> make map! [
> id 8
> count 0
> hidden false
> can_act false
> ]
> ]
> chunk_size 20
> bookmarked _
> tags []
> featured_link _
> topic_timer _
> message_bus_last_id 36
> 
> ```

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [2017年五月25日 13:35 UTC](https://meta.discourse.org/t/api-to-fetch-topic-by-page/63342/2 "2017-05-25T13:35:08Z")

</div>

Are you trying to get all the posts that belong to a topic?

This would be a good feature to add to the discourse\_api ruby gem rather than making raw api calls. There is no “Next Page” api call. What you will need to do to get the “next page” is to look at the `post_stream` part of the response:

 ![](https://global.discourse-cdn.com/meta/original/3X/8/a/8a386729157f67a290ca758d75069ed16aabb803.png)

And then you will need to call the [`/t/{id}/posts` endpoint](https://docs.discourse.org/#tag/Topics%2Fpaths%2F~1t~1%7Bid%7D~1posts.json%2Fget) and pass in a list of post\_id’s:

 ![](https://global.discourse-cdn.com/meta/original/3X/4/9/49a6ba053c8494d924069e5eff1c4f3b2e2e9d26.png)

I would recommend opening up the chrome dev tools and looking at the xhr requests on a long topic here on meta to learn how this works.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2017年五月25日 16:21 UTC](https://meta.discourse.org/t/api-to-fetch-topic-by-page/63342/3 "2017-05-25T16:21:27Z")

</div>

I wrote a [little script](https://github.com/pfaffman/discourse-downloader) that you can pass a category or a topic and it’ll download all of the posts. It was a little finicky getting all of the posts, as it seemed that the payload (sometimes?) includes posts before the first on requested.

> [@blake](#):
>
> This would be a good feature to add to the discourse\_api ruby gem rather than making raw api calls. There is no “Next Page” api call.

Sounds like a good idea. It might need to be limited to admins or something to protect from DDS attacks?

---

<div class="post-metadata">

### Author: ![gchiu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gchiu/32/95856_2.png) [@gchiu](https://meta.discourse.org/u/gchiu)
#### Post date: [2017年五月25日 18:34 UTC](https://meta.discourse.org/t/api-to-fetch-topic-by-page/63342/4 "2017-05-25T18:34:47Z")

</div>

I’m using a topic to hold a change-log which is all the commits as they come in each day from our GitHub project. I want to find the post that contains a particular commit hash. So, I’d want to search all the posts for that topic in reverse date order to find the post.

I thought it might be too expensive to search on the hash itself and extract that post that is in the topic.

I can work with the `post_stream` I guess.

---

<div class="post-metadata">

### Author: ![gchiu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gchiu/32/95856_2.png) [@gchiu](https://meta.discourse.org/u/gchiu)
#### Post date: [2017年五月25日 19:49 UTC](https://meta.discourse.org/t/api-to-fetch-topic-by-page/63342/5 "2017-05-25T19:49:55Z")

</div>

And I’ve cooked up something that works for me. It grabs the post\_stream and then searches on the last 10 posts for the topic looking for my commit hash.

[https://github.com/r3n/renclib/blob/master/scripts/changes.reb](https://github.com/r3n/renclib/blob/master/scripts/changes.reb)

---

<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: [2019年六月10日 19:16 UTC](https://meta.discourse.org/t/api-to-fetch-topic-by-page/63342/6 "2019-06-10T19:16:53Z")

</div>



---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [2019年六月10日 22:15 UTC](https://meta.discourse.org/t/api-to-fetch-topic-by-page/63342/7 "2019-06-10T22:15:55Z")

</div>


