Introduction
Managing list items in SharePoint Online is common practice, but handling user comments on those items requires an additional layer of control. Sometimes, a comment may need to be deleted, either due to inappropriate content or outdated information. In this article, we'll explore how to delete comments from a SharePoint list item using the SharePoint REST API.
In any SharePoint site, go to the List and select List Item. You can see the comment icon beside it. You can add a comment for that item.
I have added two comments on a list item. Let's take step by step solution to get and delete comments from list items.
Step 1. Create a new flow with a manual trigger flow. https://make.powerautomate.com/
Step 2. Add an action "Send an HTTP request to SharePoint" to the flow.
Step 3. Add the site URL and Api Uri.
_api/web/lists/getbytitle('List Name')/items(1)/Comments()
Step 4. Let's see the flow output after running it manually from the right panel.
Add a compose action to get the output of the HTTP request action. Add a compose action and add input as.
@{
body('Send_an_HTTP_request_to_SharePoint')?['d']?['results']
}
Run the slow and You will get all the comment details in the output of the compose action. Now we have to select the id of that comment to delete the specific comment.
Step 5. Add the site URL and Api Uri.
_api/web/lists/getbytitle('List Name')/items(1)/Comments(<Comment Id>)
Step 6. After running the flow, let's see if the comment is deleted from the list.
My Original list item comments are shown below.
After a successful flow run.
Conclusion
Deleting comments from a SharePoint list item using the REST API is a straightforward process that involves fetching the Form Digest, sending a DELETE request, and ensuring proper authentication.
Mastering these REST API operations allows for greater control over list items and comments, making it easier to build powerful custom solutions on top of SharePoint.