The discussion revolves around retrieving only top-level posts from a topic using the Discourse API. coopaloop asks if there’s a way to get the 20 most recent top-level posts without filtering replies manually. blake initially confirms there’s no direct filter but suggests using the Data Explorer plugin. riking notes the challenges due to messy metadata. Later, blake informs that a filter_top_level_replies=true query parameter is now available, providing an example API endpoint to use.
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?
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
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.
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