SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.25k stars 1.02k forks source link

SharePoint Rest API - GetChanges does not recursively show child items when a parent folder is copied in SharePoint #9039

Open jbyt1 opened 1 year ago

jbyt1 commented 1 year ago

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

SharePoint REST API

Developer environment

None

What browser(s) / client(s) have you tested

Additional environment details

GetChanges API call done through Postman

Describe the bug / error

Normally adding a folder will include all sub folders and files in the folder as separate changes in the GetChanges response. This doesn't seem to be the case when copying a parent folder in the SharePoint UI. Instead a single change is logged as an add item event. This seems to go against the change log idea with the RecursiveAll set to true. Because of this additional work is required to conditionally scan the folder tree if changes were logged from a copy or manually adding the folder.

Steps to reproduce

  1. Upload a folder with child files and folders to SharePoint
  2. Record latest change token of list after the upload is done
  3. Copy the parent folder into the same list to create a duplicate
  4. Call GetChanges for the list using SharePoint Rest API
  5. Result only displays a single change for adding the parent folder and does not recursively include child items in the folder.

Example GetChanges post call query for step 4 https://mytenant.sharepoint.com/sites/mysite/_api/web/lists/getbytitle('mylist')/getchanges

{
    "query": {
        "__metadata": {
            "type": "SP.ChangeQuery"
        },
        "Activity": true,
        "Add": true,
        "Alert": true,
        "ContentType": true,
        "DeleteObject": true,
        "FetchLimit": "1000",
        "Field": true,
        "File": true,
        "Folder": true,
        "Group": true,
        "GroupMembershipAdd": true,
        "GroupMembershipDelete": true,
        "IgnoreStartTokenNotFoundError": false,
        "Item": true,
        "LatestFirst": false,
        "List": false,
        "Move": true,
        "Navigation": true,
        "RecursiveAll": true,
        "Rename": true,
        "RequireSecurityTrim": false,
        "Restore": true,
        "RoleAssignmentAdd": true,
        "RoleAssignmentDelete": true,
        "RoleDefinitionAdd": true,
        "RoleDefinitionDelete": true,
        "RoleDefinitionUpdate": true,
        "SecurityPolicy": true,
        "Site": false,
        "SystemUpdate": false,
        "Update": true,
        "User": false,
        "View": false,
        "Web": false,

        "ChangeTokenStart": {
            "StringValue": "mylisttoken"
        }
    }
}

Expected behavior

Any copy method should include changes for any sub folders or files when RecursiveAll is set to true and should match the behaviour of when a user would manually add a folder with subfolders and files. This is to reduce the requirement to perform a tree traversal and hit the API more than necessary.

ghost commented 1 year ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

jbyt1 commented 1 year ago

@VesaJuvonen any update on triage for this or advice on what to do? Thanks.

stefan10445 commented 1 year ago

We observe the same problem. The recursively copied items are missing both in the GetChanges method and in the GetListItemChangesSinceToken method of the REST API. It seems to be a bug in SharePoint, which is existent in combination with the previously non-existent copy function in the modern UI.

stefan10445 commented 1 year ago

I have had contact with the premium support which is not able to help with this kind of issues. The support assume it's a bug, even if they can't confirm it 100%. The recommendation is to wait here on github for a response. Please look into this, it would be nice to at least get a confirmation that it is a bug.

A official guidance to use those methods for synchronizing can be found here: https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/synchronize-sharepoint-items-using-the-rest-service https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/query-sharepoint-change-log-with-changequery-and-changetoken

A detailed description of the methods is in the Specs. If you take this into account, it must be a bug: The GetListItemChanges operation is used to retrieve the list items that have been inserted or updated after the specified date and time, and that match the specified filter criteria Reference: https://learn.microsoft.com/en-us/openspecs/sharepoint_protocols/ms-listsws/41e46661-0879-46d3-98e5-b23db0e98f29

The GetListItemChangesSinceToken operation is used to return changes made to a specified list after the event expressed by the change token, if specified, or to return all the list items in the list. Reference: https://learn.microsoft.com/en-us/openspecs/sharepoint_protocols/ms-listsws/472fa848-4997-4500-a03f-d2295e127217