question

AriasRomeroDavidAContractor-1373 avatar image
0 Votes"
AriasRomeroDavidAContractor-1373 asked saldana-msft edited

How to extract historical V3Comments for each item in a sharepoint list?

Hello,

I am currently using python to create an HTTP request to pull data from a sharepoint List.
I'm able to pull all data fields on the list, with the exception of the historical comments that users have left on each record in the list.

This endpoint seems to do the job for all of the other data points that I need:
'https://graph.microsoft.com/v1.0/sites/sempra.sharepoint.com:/teams/ted/TransProjEstimating:/lists/b754c15b-7ece-4c35-839e-cdcda4288e05/items?$expand=fields'

but only retrieves the most recent comment in the historical thread of comments.

Here are the historical comments that I want (can only be viewed when in edit mode on list item) (redacted for user privacy)
96814-want.png

Here is a snap of the results that I get when I hit the graph endpoint (Note: I've highlighted relevant text in yellow):
96805-get.png

Any help in the right direction would be greatly appreciated!
Thank you.

office-sharepoint-online
want.png (159.2 KiB)
get.png (9.8 KiB)
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.

AriasRomeroDavidAContractor-1373 avatar image
0 Votes"
AriasRomeroDavidAContractor-1373 answered

Hi @MichaelHan-MSFT,

Looks like this solution did not work,
But it did point me in the right direction!

This link explains why this approach does not work:
https://docs.microsoft.com/en-us/graph/query-parameters#expand-parameter
tl;dr: $expand can only take one expandParam at a time


As mentioned above this led me to a solution, which is found here: https://docs.microsoft.com/en-us/graph/api/listitem-list-versions?view=graph-rest-1.0&tabs=http
Instead of expanding the entire list, looks like each item has its own version history and can be pulled in
after an initial scrape of all List Ids:
1. // all_listItem_ids = Get sites/{site-id}/lists/{list-id}/items?$expand=fields(select=id)

Then,
2. For listItemId in all_listItem_ids:
// GET /sites/{site-id}/lists/{list-id}/items/{listItemId}/versions


Thank you for your help!!


Best,
David Arias Romero


· 1
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.

Hi @AriasRomeroDavidAContractor-1373,

Glad that you found the solution to this. Thanks for the sharing :)

I have converted your comment to answer, you could accept it as answer. It would be helpful to others who have similar issues in the future.

0 Votes 0 ·
MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered MichaelHan-MSFT converted comment to answer

Hi @AriasRomeroDavidAContractor-1373,

The historical comments are stored in the history of list items, known as versions of ListItem. You could list versions of a ListItem by referring to this article: Listing versions of a ListItem

So in your graph endpoint, add versions in expand parameter, like this:

 ?$expand=fields,versions


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.




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.