0

I'm using the following api to successfully get file data:

https://acme.sharepoint.com/sites/my-site/_api/Web/Lists(guid'xxx')/files('yyy')

This is a docx file on which I've posted comments using the web console.

How can I fetch these comments using the rest api? I tried appending /comments to the url, but I'm getting the following 404 error:

{
    "error": {
        "code": "-1, Microsoft.SharePoint.Client.ResourceNotFoundException",
        "message": {
            "lang": "en-US",
            "value": "Cannot find resource for the request Comments."
        }
    }
}
Mugen
  • 8,301
  • 10
  • 62
  • 140

2 Answers2

1

The Comments() endpoint currently exists only under the Items() endpoint and not under the Files() endpoint. Basically, you can access the Comments() functionality only under the below endpoint:

GET https://{site_url}/_api/web/lists/GetByTitle({list_title})/items({item_id})/Comments

You can easily test the above in a PowerAutomate scenario with a Send Http Request to SharePoint actions.

In the below example I attempt to target the file in the document library: erroneosu call

On the other hand, if I attempt to target the file based on the List Item Id that it got in the document library I will get the below response: correct call

As you can see from the above, I am also able to target a specific comment that I left.

Please take note of the below

The Comments() endpoint is not available for MS resources, meaning docx, excels and such files. It is only available for non-MS resource files like pdfs, txts and so on. I am not sure why this rule is in effect but, my best guess would be because there is a "commenting" functionality provided within a Word Document, for example.

You could find a bit more info about the above here.

jimas13
  • 597
  • 5
  • 19
0

This used to work for me about 14 months from now, but now it doesn't any more - I do not get an error for my API call, but even though the item (.aspx page) DOES have comments, the results array is alway null.

I've been able to get all other types of statistics (e.g. via the "/likedByInformation" endpoints for likes etc.) but this one keeps failing me.

Have also tried "/_api/web/lists/GetByTitle('Site Pages')/GetItemById(x)/Comments" instead of "items(x)/Comments" to no avail.

Many thanks for anyone who can help! Since I'm a new user, my screenshot has been blocked, so THIS is what sadly didn't work:

_api/lists/getbytitle('SitePages')/items(47)/Comments

Result: HTTP 200 ok, outputs:

{
  "d": {
    "results": []
  }
}

P.S.: It's NOT "SitePages" that's the issue as I can pull all other information for this item bar "Comments"

  • Hi, you shouldn't post a question as an answer, that won't get you much traffic :) generally its better to open your own question – Mugen Jul 05 '23 at 08:28
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 18 '23 at 21:13