question

matthowell-6829 avatar image
0 Votes"
matthowell-6829 asked matthowell-6829 edited

Sharepoint REST api - post a like on a site page comment

I can like a page using:
/_api/web/lists/getByTitle('SitePages')/GetItemById(722)/like

Modern pages also allow users to like a comment but this api call doesn't work:
/_api/web/lists/getByTitle('SitePages')/GetItemById(<pageid>)/Comments(<commentid>)/like

Error:
"error": {
"code": "-2147024891, System.UnauthorizedAccessException",
"message": {
"lang": "en-US",
"value": "Attempted to perform an unauthorized operation."
}

For this function Msft references a really long ID - but surely there's an easier way?
"ID":"1.94fdcc5fc39b4a2c99ae4570caf02321.d0a03fb1761a404a9a8e7f9f5ec58e17.5a1067e8af65410b9e2ba6a74a4b718a.0c37852b34d0418e91c62ac25af4be5b.9dbfb5598e2248d7b57eee57abf2e7c1.31.31.S-1-5-21-124525095-708259637-1543119021-565461"

There's no id like this in the comments json response - the comments "id" is a simple integer.



office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered matthowell-6829 edited

Hi, @matthowell-6829,

Just did a test on my end, the like a comment endpoint worked well for me. From the error message, looks like you do not have enough access to like a comment.

110075-image.png



If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (18.6 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MichaelHan-MSFT Hmm, don't think that's it. I'm able to like a page using the same authorization, and same user can like a comment in the browser. I'm SP Admin and site coll admin for this site and app is registered in Azure AD with write access delegated for all users.

0 Votes 0 ·

What authorization did you use? Are you using app access to call the api?

If you use user authorization, would it work?

0 Votes 0 ·

Figured it out - the api call was correct but there was some corruption in the access code (from registered Azure AD app). Using Postman, it worked in one workspace so I redid the Auth header and it worked in the other workspace. I'd been pasting in the access code, but I think an extra space got introduced somehow.

0 Votes 0 ·