You wrote you have already the particular question you need the replies for. Then you should now its ID as well. Using that ID you can filter the items for the replies for the particular question via REST (assuming the ID is 234):
http://YourServer/YourSite/_api/Web/Lists/GetByTitle('TitleOfYourDiscussionBoard')/Items?$filter=ParentItemID eq 234
Note, that this query returns only the direct responses to the question, but not the replies for the responses.
To understand the other approach (returning any responses that belong to a question, independently from the position in the structure), you should first know, that dicsussion board threads are organized as a folder structure. The threads (the questions) are folders, and the answers for the questions are items within the corresponding folder.
You can get the folder objects for your question as:
http://YourServer/YourSite/_api/Web/Lists/GetByTitle('TitleOfYourDiscussionBoard')/Items(234)/Folder
See the ServerRelativeUrl
property of the returned item. Assume it is '/YourSite/Lists/DiscussionBoard/Question234
'.
Next send a POST
(not a GET
!) request to the server with the URL below to get all items within the folder (that means, all answers for the particular question):
/_api/web/Lists/GetByTitle('DiscussionBoard')/GetItems(query=@v1)?@v1={"ViewXml":"<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='FileDirRef' /><Value Type='Text'>/YourSite/Lists/DiscussionBoard/Question234</Value></Eq></Where></Query></View>"}
Don't forget to escape the apostrophes in this text when using it in code as string!
var request = "/_api/web/Lists/GetByTitle('DiscussionBoard')/GetItems(query=@v1)?@v1={\"ViewXml\":\"<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='FileDirRef' /><Value Type='Text'>/YourSite/Lists/DiscussionBoard/Question234</Value></Eq></Where></Query></View>\"}";
Alternatively (as long as you are working with JavaScript
and not C#
) you can build up a JavaScript
object and stringify it via JSON.stringify
.:
var query = {
ViewXml: "<View Scope='Recursive'><Query><Where><Eq><FieldRef Name='FileDirRef' /><Value Type='Text'>/YourSite/Lists/DiscussionBoard/Question234</Value></Eq></Where></Query></View>"
};
var request = "/_api/web/Lists/GetByTitle('DiscussionBoard')/GetItems(query=@v1)?@v1=" + JSON.stringify(query);