Retrieving top level replies on a topic

AI-generated summary

Retrieving Top Level Replies on a Topic

ManishTripathy is seeking to fetch first-level replies made on a topic in Discourse. However, using the GET http://discourse-url/posts/{post_id}/replies.json API call with reply_to_post_number as null returns an empty array. This is because Discourse treats top-level replies as posts, not replies.

To work around this, ManishTripathy discovered that setting reply_to_post_number to 1 allows the API call to successfully retrieve first-level replies. However, this change may fundamentally alter the post structure in Discourse.

ManishTripathy is concerned that this change might break other Discourse functionalities. Despite not currently observing any issues, they are seeking help to understand potential side effects of converting posts to replies by setting reply_to_post_number to 1 instead of null.

I have a requirement where we need to fetch all the first level replies made on a topic. Now when we create a new topic, it also creates a post. In order to create a first level reply on the topic, I make the below API call

POST http://discourse-url/posts/
{
“raw”: “This is a first level reply on a topic”,
“topic_id”: 1234,
“reply_to_post_number”: null
}

Now to retrieve the first level replies, I make the below call with post_id as the ID of the first post created for the topic. This post has the post_number as 1

GET http://discourse-url/posts/{post_id}/replies.json

But this returns me an empty array. This is understandable as Discourse treats the top level replies on a topic as posts and not replies. In Discourse terminology, “replies” are made on posts and “posts” are made on topics.

I have found a workaround for the same. Rather than sending reply_to_post_number as null, if I send it as 1, the API call for replies also works fine. Below is the sample request:

POST http://discourse-url/posts/
{
“raw”: “This is a first level reply on a topic”,
“topic_id”: 1234,
“reply_to_post_number”: 1
}

Now I could fetch the first level replies for this topic by making the below API call

GET http://discourse-url/posts/{post_id}/replies.json

Going by the answer here Posts vs Replies vs Topic, I feel I have made a fundamental change to the structure of the posts in Discourse now.
My question is: Can this change break any other functionality in Discourse? Currently I don’t see any issues in the website with this change. But is there something that I might be missing and should be careful about?

Could you please help me understanding the side effects of converting posts to replies by changing reply_to_post_number as 1 instead of null?