Retrieving top level replies on a topic

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?

2 Likes

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?