SharePoint Rest API: GetChanges

prakash prajapat 0 Reputation points
2024-09-21T16:23:02.46+00:00

Imagine we have a file in a folder named FOLDER_B, and FOLDER_B is located inside another folder, FOLDER_A. I am moving a file from FOLDER_B to FOLDER_A (parent of FOLDER_B). Afterward, I attempt to retrieve the file changes by making the following API call to:

https://mindtickledotcom.sharepoint.com/sites/<sitename>/api/web/GetFolderById('folder id of FOLDER_B')/GetChanges

The JSON payload for the request is:

{
  "query": {
    "Add": true,
    "SystemUpdate": true,
    "DeleteObject": true,
    "Move": true,
    "Rename": true,
    "Restore": true,
    "Item": true,
    "File": true,
    "Folder": true,
    "ChangeTokenStart": {
      "StringValue": "1;3;3df964e0-3257-415d-a8b0-538d5ddabe43;638625074960000000;1055416306"
    }
  }
}

The response I receive is:

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

My query is that the response doesn't contain the Move ChangeType. What parameters or adjustments should I make to capture the Move change type?

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,969 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ling Zhou_MSFT 17,135 Reputation points Microsoft Vendor
    2024-09-24T01:36:27.1133333+00:00

    Hi @prakash prajapat,Thank you for posting in this community.

    According to this document: Working with folders by using REST, the folder doesn't seem to support this GetChanges Rest API.

    Instead, I found that the SharePoint SDK (Client-Side Object Model or CSOM) support GetChanges for folders.

    User's image

    You can refer to this article: Enumerating changes that happened in SharePoint to use SDK to get folder changes.

    Hope this helps.


    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.


  2. Ionut Andrei Vaduva 0 Reputation points
    2024-10-03T08:15:18.0833333+00:00

    The key to detecting when a file is moved between folders in SharePoint Online that has worked for me is to use the Rename parameter in the Change API, as SharePoint treats file moves as a change in the file's name or location:

    var changeQuery = new ChangeQuery(false, false)

    {

    Item = true, // Detect changes in items

    DeleteObject = true, // Detect deletions

    Restore = true, // Detect restores

    Add = true, // Detect additions

    Update = true, // Detect updates

    File = true, // Detect changes in files

    Rename = true, // Used to detect if a document has been moved or renamed

    ChangeTokenStart = lastChangeToken, // Previous change token to avoid duplicates

    };

    var changes = documentLibrary.GetChanges(changeQuery);

    context.Load(changes);

    await context.ExecuteQueryAsync();

    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.