# Getting all posts in a topic

**URL:** https://meta.discourse.org/t/getting-all-posts-in-a-topic/358385
**Category:** Development
**Tags:** rest-api
**Created:** [March 21, 2025, 7:48pm UTC](https://meta.discourse.org/t/getting-all-posts-in-a-topic/358385 "2025-03-21T19:48:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tyler.lamparter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tyler.lamparter/32/485862_2.png) [@tyler.lamparter](https://meta.discourse.org/u/tyler.lamparter)
#### Post date: [March 21, 2025, 7:48pm UTC](https://meta.discourse.org/t/getting-all-posts-in-a-topic/358385/1 "2025-03-21T19:48:52Z")

</div>

In case anyone else is wondering, the [get a single topic](https://docs.discourse.org/#tag/Topics/operation/getTopic) API supports pagination by using a `page` parameter. It starts at 1 and returns a 404 when there are no more pages. I needed this to get all posts for a given topic, as the default return limit is 20 posts.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 21, 2025, 7:55pm UTC](https://meta.discourse.org/t/getting-all-posts-in-a-topic/358385/2 "2025-03-21T19:55:47Z")

</div>

> [@tyler.lamparter](#):
>
> I needed this to get all posts for a given topic

I believe this is not possible unless you use #data-explorer to return a query result with the API. 🙂

---

<div class="post-metadata">

### Author: ![tyler.lamparter](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tyler.lamparter/32/485862_2.png) [@tyler.lamparter](https://meta.discourse.org/u/tyler.lamparter)
#### Post date: [March 21, 2025, 8:14pm UTC](https://meta.discourse.org/t/getting-all-posts-in-a-topic/358385/3 "2025-03-21T20:14:57Z")

</div>

It is possible by using the API I linked and then passing the page parameter. The API docs don’t mention that you can pass the page parameter, but it works exactly as you would expect. I made this post so others would know and wouldn’t have to defer to the [data explorer](https://meta.discourse.org/t/32566?silent=true).

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [March 21, 2025, 8:26pm UTC](https://meta.discourse.org/t/getting-all-posts-in-a-topic/358385/4 "2025-03-21T20:26:09Z")

</div>

Oh, I misread your post. I thought you were looking for a way to return ALL posts from a topic at once.

Here’s a script example using the API pagination (not exactly the same query, as it returns posts from a user and each page contains 50 posts, not 20):

> [@Searching for image urls in topics](https://meta.discourse.org/t/searching-for-image-urls-in-topics/346912/9):
>
> You don’t need an API key to do searches. I’m not sure having an API key could help you resolve your issue more easily. Here’s an robot example Python script that loops my posts (1 post every 3 sec) on meta and returns those having the substring upload:// in the raw content: import requests import time def fetch\_posts(page): url = f"https://meta.discourse.org/search.json?q=%40cocoquark&page={page}" response = requests.get(url) return response.json() def fetch\_post\_content(pos…
