Microsoft Graph copy sharepoint files item not found and other errors

Janet 1 Reputation point
2021-10-04T18:53:48.387+00:00

I am attempting to use Microsoft graph to copy sharepoint files from one folder to one of the subfolders. I followed the syntax that was documented on the Microsoft site. I received the error that the "item was not found" and the I also included the driveid and got the error "item already exists". I was following the instructions provided in https://developer.microsoft.com/en-us/microsoft-365/blogs/microsoft-graph-mailbag-copy-move-files-and-folders-in-sharepoint-online/.

item not found
POST /sites/{siteId}/drive/items/{itemId}/copy
REQUEST BODY
{
"parentReference": {
"driveId": "<driveID>",
"id": "<driveID>"
},
"name": "<filename>"
}

item already exists
POST /sites/{siteId}/drive/{driveid}/items/{itemId}/copy
REQUEST BODY
{
"parentReference": {
"driveId": "<driveID>",
"id": "<driveID>"
},
"name": "<filename>"
}

https://graph.microsoft.com/v1.0/sites/coxcomminc.sharepoint.com,c80fc32c-7057-4cc6-881f-3a1c9ae3c377,fbecb94e-b16f-4be1-ab7b-4e9be34df31f/drive/items/0175UB7YWSAPE26ILFCREL73RWHBRRT3TI/copy

{
"parentReference": {
"driveId": "b!LMMPyFdwxkyIHzocmuPDd0657PtvseFLq3tOm-NN8x_vtqchuBJ2Rr-ZJOA6WIQ8",
"id": "0175UB7YV6Y2GOVW7725BZO354PWSELRRZ"
},
"name": "test.doc"

}

{
"error": {
"code": "itemNotFound",
"message": "The resource could not be found.",
"innerError": {
"date": "2021-10-01T12:00:37",
"request-id": "c410b4f9-029e-48e0-bdc9-bf4de4a48973",
"client-request-id": "ad0191db-614c-e3e4-c6e1-fcfa5b7e78c5"
}
}
}

{
"error": {
"code": "nameAlreadyExists",
"message": "The specified item name already exists.",
"innerError": {
"date": "2021-09-30T16:37:18",
"request-id": "57a3dd90-2eaf-4e77-b0e6-50c3b4641584",
"client-request-id": "fc3e1a88-1bea-3820-5241-ed8a46de9ded"
}
}
}

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,740 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,761 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Alejandro Quiroga 5 Reputation points
    2023-05-23T11:29:41.82+00:00

    I had the same issue here, I did this call:

    POST

    https://graph.microsoft.com/v1.0/drives/**{DriveContainingTheItemToCopy}**/items/**{IdOfTheItemToCopy}**/copy

    Body:

    {
        "parentReference": {
            "driveId": "{DestinationDriveId}",
            "id": "{DestinationFolderId}"
        },
        "name": "{NewNameOfTheItem}"
    }
    

    The issue happened to be that the NAME of the destination folder had . and #, I don't know which of them was the culprit, but when I renamed it removing those characters, I could copy the item with the same values and parameters.

    It's kinda weird because the GET works well and it retreives succesfully the ID of the folder despite having those characters, must be some bug in the COPY endpoint.

    1 person found this answer helpful.
    0 comments No comments

  2. RaytheonXie_MSFT 31,686 Reputation points Microsoft Vendor
    2021-10-05T03:14:21.303+00:00

    Hi @Janet ,
    Per my test, '/drive' set the 'Document' library as default. The url can't get the library of our resource.
    We can get our file copyed by following url:

    POST /sites/{siteId}/drives/{drive-id}/items/{itemId}/copy  
    

    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.

    0 comments No comments