2

I have a modern site page where 600+ comments are there, when I try to fetch the comments using below REST API it always returns top 200 comments only.

<siteurl>/_api/web/Lists('GUID')/GetItemById('Item ID')/Comments?$skiptoken=Paged=TRUE&p_ID=300&$expand=replies,likedBy,replies/likedBy&$inlineCount=AllPages&$top=300

I can verify the other comments seperately using below format also

<siteurl>/_api/web/lists('GUID')/GetItemById('Item ID')/Comments(10)

I need a way to get all comments via single shot or using pagination. I have tried most of the combination using skip, skiptoken, top and rowlimit but nothing returns more than 200. Let me know if this limit can be extended via powershell or in central admin too.

Appreciate any suggestions on exporting comments via any means also!

1
  • Any suggestions pls?
    – Sivanrv
    Feb 20, 2020 at 11:06

1 Answer 1

0

yes, it's a pain - limited to 200 per call, so you have to use pagination. I did this in Power Automate - the concept will be the same for however you do the rest call.

When you do the first call:

https://your-tenant.sharepoint.com/sites/your-site/_api/lists/getbytitle('Site Pages')/items(your-page-id)/comments?$top=100

Have a look at the payload you get back. If there are more than 100 comments on your page ($top=100), you'll get back something like this:

"__next": "https://your-tenant.sharepoint.com/sites/your site/_api/lists/getbytitle(%27Site%20Pages%27)/items(530)/comments?%24skiptoken=AAAAAL8BAAAACCAAoPNJMRX820g1&%24top=100"

So you have to get the value of '__next' and use that as the URL to call the next batch (in my case, I'm getting 100 at a time). If there are no more comments to retrieve, this will be blank, so you'll have to loop until it's empty. This is the function I used in Power Automate to get the '__next' value, or '' if its null.

decodeUriComponent(coalesce(body('GetComments1')?['d']?['__next'], ''))

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.