I have a Blog subsite of my main website. I am trying to get the Top 2 blog posts along with the number of comments and actual comments. I am able to get Number of Comments with the field NumCommentsId but along with it i also want Comments to be part of the JSON object returned from the REST API. This is how my url looks like:
http://mywebsite-dev/blog/_api/web/lists/getByTitle('Posts')/items?$select=Title,Body,Id,LikesCount,NumCommentsId
This is how the returned JSON looks like:
{
"d": {
"results": [
{
"__metadata": {
"id": "Web/Lists(guid'862870c0-e56b-48ca-9da4-b337d05984aa')/Items(2)",
"uri": "http://mywebsite-dev/blog/_api/Web/Lists(guid'862870c0-e56b-48ca-9da4-b337d05984aa')/Items(2)",
"etag": "\"1\"",
"type": "SP.Data.PostsListItem"
},
"Id": 2,
"Title": "Blog 1",
"Body": "<div class=\"ExternalClass30B2DE63AD2D4EE1AC4DD2735266245C\"><p>This is my blog 1•</p></div>",
"NumCommentsId": 0,
"LikesCount": null,
"ID": 2
},
{
"__metadata": {
"id": "Web/Lists(guid'862870c0-e56b-48ca-9da4-b337d05984aa')/Items(3)",
"uri": "http://mywebsite-dev/blog/_api/Web/Lists(guid'862870c0-e56b-48ca-9da4-b337d05984aa')/Items(3)",
"etag": "\"1\"",
"type": "SP.Data.PostsListItem"
},
"Id": 3,
"Title": "Blog 2",
"Body": "<div class=\"ExternalClass9FDE8E9403FF43F3BEE2BC24798EDA16\"><p>This is second cloud blog•</p></div>",
"NumCommentsId": 3,
"LikesCount": null,
"ID": 3
}
]
}
}
I want actual comments to be returned in this JSON object. Something like this:
{
"d": {
"results": [
{
"__metadata": {
"id": "Web/Lists(guid'862870c0-e56b-48ca-9da4-b337d05984aa')/Items(2)",
"uri": "http://mywebsite-dev/blog/_api/Web/Lists(guid'862870c0-e56b-48ca-9da4-b337d05984aa')/Items(2)",
"etag": "\"1\"",
"type": "SP.Data.PostsListItem"
},
"Id": 2,
"Title": "Blog 1",
"Body": "<div class=\"ExternalClass30B2DE63AD2D4EE1AC4DD2735266245C\"><p>This is my blog 1•</p></div>",
"NumCommentsId": 0,
"Comments":{}
"LikesCount": null,
"ID": 2
},
{
"__metadata": {
"id": "Web/Lists(guid'862870c0-e56b-48ca-9da4-b337d05984aa')/Items(3)",
"uri": "http://mywebsite-dev/blog/_api/Web/Lists(guid'862870c0-e56b-48ca-9da4-b337d05984aa')/Items(3)",
"etag": "\"1\"",
"type": "SP.Data.PostsListItem"
},
"Id": 3,
"Title": "Blog 2",
"Body": "<div class=\"ExternalClass9FDE8E9403FF43F3BEE2BC24798EDA16\"><p>This is second cloud blog•</p></div>",
"NumCommentsId": 3,
"Comments":[
{
"Id":1,
"Title":"My Comment Title",
"Body":"My Comment Body"
},
{
"Id":2,
"Title":"My second Comment Title",
"Body":"My second Comment Body"
},
{
"Id":3,
"Title":"My third Comment Title",
"Body":"My third Comment Body"
},
]
"LikesCount": null,
"ID": 3
}
]
}
}
Is this possible? If so, how?