Retrieve Modern SharePoint list item comments using REST

Recently someone had posted on a SharePoint support forum asking whether or not it was possible to retrieve the new modern list item comments programmatically. In case you haven’t seen this yet, Microsoft has introduced the ability for users to add comments to the activity feed on list items in SharePoint.

To add a comment, navigate to your list item, open up the information pane and scroll to bottom. You will see the activity feed where you can add, remove and view comments from yourself and others on a list item.

While the endpoint is not yet documented, it is indeed possible to interact with these comments. However, be aware, the comments are not apart of the list item object in REST, you must call a different endpoint to retrieve the values.

Get list item comments using REST

To retrieve all of the comments on a list item using REST, you can make a GET call the following API endpoint.

/_api/web/lists/getbytitle('<ListName>')/items(<ItemID>)/GetComments()

Here is the response

{
    "d": {
        "results": [{
            "__metadata": {
                "id": "https://yourcompanyname.sharepoint.com/sites/SiteName/_api/web/lists('43f52951-64fa-4362-b03e-4fefde369da9')/GetItemById(1)/Comments(1)",
                "uri": "https://yourcompanyname.sharepoint.com/sites/SiteName/_api/web/lists('43f52951-64fa-4362-b03e-4fefde369da9')/GetItemById(1)/Comments(1)",
                "type": "Microsoft.SharePoint.Comments.comment"
            },
            "likedBy": {
                "__deferred": {
                    "uri": "https://yourcompanyname.sharepoint.com/sites/SiteName/_api/web/lists('43f52951-64fa-4362-b03e-4fefde369da9')/GetItemById(1)/Comments(1)/likedBy"
                }
            },
            "replies": {
                "results": []
            },
            "author": {
                "__metadata": {
                    "type": "SP.Shring.Principal"
                },
                "email": "beau@yourcompanyname.com",
                "expiration": null,
                "id": 6,
                "isActive": true,
                "isExternal": false,
                "jobTitle": null,
                "loginName": "i:0#.f|membership|beau@yourcompanyname.com",
                "name": "Beau Cameron",
                "principalType": 1,
                "userId": null,
                "userPrincipalName": null
            },
            "createdDate": "2020-12-15T21:32:05.52Z",
            "id": "1",
            "isLikedByUser": false,
            "isReply": false,
            "itemId": 1,
            "likeCount": 0,
            "listId": "43f52951-64fa-4362-b03e-4fefde369da9",
            "mentions": {
                "__metadata": {
                    "type": "Collection(Microsoft.SharePoint.Comments.Client.Identity)"
                },
                "results": []
            },
            "parentId": "0",
            "replyCount": 0,
            "text": "Add a new comment"
        }]
    }
}

One thought on “Retrieve Modern SharePoint list item comments using REST

Leave a comment