SharePoint Rest API: GetListItemChangesSinceToken

Saurabh Gangwal 5 Reputation points
2023-09-18T15:28:32.0333333+00:00

I'm trying to fetch file changes that happens under given folder path in SharePoint document library. I'm using below call

POST https://{domain}/sites/{siteName}/_api/web/lists/getbytitle('Drive')/GetListItemChangesSinceToken

JSON payload to request is

{
    "query": {
        "ViewName": "",
        "QueryOptions": "<QueryOptions><Folder>Drive/Audit Test</Folder></QueryOptions>",
        "ChangeToken": "1;3;b39abb17-7a24-4e9a-8a6e-a75b22bffd11;638306253560530000;905277314"
    }
}

In response, I get below XML.

<?xml version="1.0" encoding="utf-8" ?><GetListItemChangesSinceTokenResult><listitems MinTimeBetweenSyncs='0' RecommendedTimeBetweenSyncs='180' MaxBulkDocumentSyncSize='500' MaxRecommendedEmbeddedFileSize='500' EffectivePermMask='ViewListItems, OpenItems, ViewVersions, ViewFormPages, Open, ViewPages, ViewUsageData, BrowseUserInfo, UseClientIntegration, UseRemoteAPIs, OpenWebOnly, ViewItemsRequiresOpen' xmlns:s=''
     xmlns:dt=''
     xmlns:rs='urn:schemas-microsoft-com:rowset'
     xmlns:z='#RowsetSchema'>
<Changes LastChangeToken="1;3;b39abb17-7a24-4e9a-8a6e-a75b22bffd11;638306269242700000;905285618">
<Id ChangeType="Restore" UniqueId="{F856392A-5F48-471F-BD2A-ADECECBD4EF1}">10</Id>
<Id ChangeType="Restore" UniqueId="{F856392A-5F48-471F-BD2A-ADECECBD4EF1}">10</Id>
<Id ChangeType="Rename" UniqueId="{F856392A-5F48-471F-BD2A-ADECECBD4EF1}">10</Id>
<Id ChangeType="Rename" UniqueId="{F856392A-5F48-471F-BD2A-ADECECBD4EF1}">10</Id>
<Id ChangeType="Rename" UniqueId="{3141DD47-B316-472D-9B45-CF1F63E4DE93}">9</Id>
<Id ChangeType="Delete" UniqueId="{F856392A-5F48-471F-BD2A-ADECECBD4EF1}">10</Id>
<Id ChangeType="Delete" UniqueId="{3141DD47-B316-472D-9B45-CF1F63E4DE93}">9</Id>
</Changes>
<rs:data ItemCount="1">
   <z:row  />
</rs:data>
</listitems></GetListItemChangesSinceTokenResult>

As you can see it returns ChangeType for a file or a folder.

Queries:

  1. How to get response in JSON, instead of XML format. I did set HTTP request header to Accept: "application/json" but it didn't worked .
  2. File or Folder Move events
    I moved one file from source folder to destination folder. When I check the changes under source folder I saw one rename event and one delete event for that file. see above response for UniqueId="{3141DD47-B316-472D-9B45-CF1F63E4DE93}. Isn't there concrete move type. Something like ChangeType="Move". Also I want to know source and destination location of moved file or folder. Is this possible?
  3. Changes only displays file/folder UniqueId and ChangeType. Is it possible to fetch event timestamp as well?
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,675 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,968 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ChengFeng - MSFT 5,020 Reputation points Microsoft Vendor
    2023-09-19T07:59:38.9566667+00:00

    Hi @Saurabh Gangwal

    For the first question:

    Please try adding this to your title:

    Accept: "application/json;odata=verbose"
    Content type: "application/json"
    

    For the second question

    To get file or folder move events, you need to use the GetChanges method instead of the GetListItemChangesSinceToken method. The GetChanges method returns a collection of SP.Change objects that represent changes to a list or library.

    For the third question

    You need to use the SP.Change object's Time property. This property returns a date and time value specifying when the change occurred


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.

    Best Regards

    Cheng Feng


  2. Eyal Alaluf 0 Reputation points
    2024-08-26T14:55:07.59+00:00

    In addition to the above answer about the headers.

    It seems like you need to specify the ViewFields. You got a response that 1 item was modified, but no field details since you didn't ask for field. See https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/cc264031(v=office.14)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.