Graph API - Sharepoint PATCH item with parentReference not working

Shadi Rashed 66 Reputation points
2024-07-24T16:03:11.1933333+00:00

The following request used to work. Now it still responds with success message, but it only updates the name, but the update of the parentReference gets ignored and so the driveItem is not moved to the target folder (target and source are in the same drive).

Could you please help understand why this request suddenly stopped working?

PATCH https://graph.microsoft.com/v1.0/drives/b!LC62G3CE0EiQRNFP5dfUEUouuZ5OmV5Iiuq4mF9cdQqTepxB3FfEQYL-j-Ux9iB-/items/01LYPJAACG2BF3LAFBNZCYVU5463LSPZIV

REQUEST

{

"parentReference": {

    "id": "01LYPJAACWEBJLEIHOWJALYQXCRAHLURKO"

},

"name": "TEST456"

}

RESPONSE

{

"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives('b%21LC62G3CE0EiQRNFP5dfUEUouuZ5OmV5Iiuq4mF9cdQqTepxB3FfEQYL-j-Ux9iB-')/items/$entity",

"createdDateTime": "2024-07-24T15:27:03Z",

"eTag": "\"{B54BD046-A180-456E-8AD3-BCF6D727E515},7\"",

"id": "01LYPJAACG2BF3LAFBNZCYVU5463LSPZIV",

"lastModifiedDateTime": "2024-07-24T16:01:07Z",

"name": "TEST456",

"webUrl": "redacted",

"cTag": "\"c:{B54BD046-A180-456E-8AD3-BCF6D727E515},0\"",

"size": 0,

"createdBy": {

    "application": {

        "id": "redacted",

        "displayName": "redacted"

    },

    "user": {

        "email": "redacted",

        "id": "redacted",

        "displayName": "redacted"

    }

},

"lastModifiedBy": {

    "application": {

        "id": "redacted",

        "displayName": "redacted"

    },

    "user": {

        "email": "redacted",

        "id": "redacted",

        "displayName": "redacted"

    }

},

"parentReference": {

    "driveType": "documentLibrary",

    "driveId": "b!LC62G3CE0EiQRNFP5dfUEUouuZ5OmV5Iiuq4mF9cdQqTepxB3FfEQYL-j-Ux9iB-",

    "id": "01LYPJAAAQH3DGY5UTKRBYKM737YHR65VJ",

    "name": "To be done",

    "path": "redacted",

    "siteId": "redacted"

},

"fileSystemInfo": {

    "createdDateTime": "2024-07-24T15:27:03Z",

    "lastModifiedDateTime": "2024-07-24T16:01:07Z"

},

"folder": {

    "childCount": 0

},

"shared": {

    "scope": "users"

}

}

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,478 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CharanyaB-MSFT 1,886 Reputation points Microsoft Vendor
    2024-07-29T16:47:39.0233333+00:00

    Hello @Shadi Rashed,

    Thank you for reaching Microsoft!

    I attempted the PATCH request for drive/{drive-id}/items/{item-id} and was successful in moving the file. Refer to the screenshots provided below:

    The screenshot below displays the parent reference ID of the CIPost.docx document before using move file Graph API.

    User's image

    The screenshot below indicates that the document has been renamed and transferred to a different folder using Graph API.

    User's image

    I suggest you recheck the id and also If a file with the same name already exists in the target directory, you might need to handle conflicts by setting the conflictBehavior parameter to replace or rename.

    Documentation reference: https://learn.microsoft.com/en-us/graph/api/driveitem-move?view=graph-rest-1.0&tabs=http

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments