# Get only top level posts in topic via discourse API

**URL:** https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319
**Category:** Development
**Tags:** rest-api
**Created:** [April 27, 2018, 4:46pm UTC](https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319 "2018-04-27T16:46:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![coopaloop](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@coopaloop](https://meta.discourse.org/u/coopaloop)
#### Post date: [April 27, 2018, 4:46pm UTC](https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319/1 "2018-04-27T16:46:19Z")

</div>

I would like to be able to get the 20 most recent posts that are top level on a topic without having to recursively re-fetch and filter post replies until I have 20. Is there a filter for this and I have just missed it somewhere in the api?

Right now it just looks like the stream array in response includes post replies by post number. So, if I have 4 posts, [1,2,3,4] and post a reply to post 1, the stream will now be [1,2,3,4,5] and the only way I can tell that 5 is a reply to 1 is by examining the post itself, finding “reply\_to\_post\_number”=\>1 and filtering it out. Am I missing something?

---

<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: [April 27, 2018, 6:06pm UTC](https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319/2 "2018-04-27T18:06:46Z")

</div>

> [@coopaloop](#):
>
> the only way I can tell that 5 is a reply to 1 is by examining the post itself, finding “reply\_to\_post\_number”=\>1 and filtering it out. Am I missing something?

That is correct. There is not a filter that can be added to the topic endpoint to get what you are after. However we do have the

> [@Discourse Data Explorer](https://meta.discourse.org/t/data-explorer-plugin/32566):
>
> discourse2Summary Discourse [Data Explorer](https://meta.discourse.org/t/32566?silent=true) allows you to make SQL queries against your live database, allowing for up-to-the-minute stats reporting.open_bookInstall Guide This plugin is bundled with Discourse core. There is no need to install the plugin separately.information_source If you’re looking for examples or support for any custom queries, you can find lots of topics in our #data-reporting category under the #sql-query tag. If there’s not one to suit your par…

which you could use to write a sql query to get what you are after. You can then save that query and hit the api endpoint for the saved query and pass it a topic\_id as a param.

---

<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: [April 27, 2018, 6:08pm UTC](https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319/3 "2018-04-27T18:08:30Z")

</div>

There isn’t a real way to get what you actually want out of this, because the metadata is messy, and people are messy and don’t really care about your analytics too much 😉

---

<div class="post-metadata">

### Author: ![coopaloop](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@coopaloop](https://meta.discourse.org/u/coopaloop)
#### Post date: [April 30, 2018, 4:30pm UTC](https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319/4 "2018-04-30T16:30:52Z")

</div>

Thanks, I will give this a shot.

---

<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: [October 6, 2020, 8:29am UTC](https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319/5 "2020-10-06T08:29:56Z")

</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: [October 23, 2020, 10:12pm UTC](https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319/6 "2020-10-23T22:12:43Z")

</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: [March 17, 2022, 1:46pm UTC](https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319/7 "2022-03-17T13:46:37Z")

</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: [March 17, 2022, 1:48pm UTC](https://meta.discourse.org/t/get-only-top-level-posts-in-topic-via-discourse-api/86319/8 "2022-03-17T13:48:57Z")

</div>

> [@coopaloop](#):
>
> I would like to be able to get the 20 most recent posts that are top level on a topic without having to recursively re-fetch and filter post replies until I have 20. Is there a filter for this and I have just missed it somewhere in the api?

We now have the `filter_top_level_replies=true` query parameter that will handle this for you.

Here is an example of it here on meta [https://meta.discourse.org/t/linkify-words-in-post/82193.json?filter\_top\_level\_replies=true](https://meta.discourse.org/t/linkify-words-in-post/82193.json?filter_top_level_replies=true)
