Search code examples
azuremicrosoft-graph-apionedrive

OneDrive GRAPH API - 400 when copying file inside OneDrive


I receive for the below request 400 Bad Request. I want to copy a file with an item-id to a directory identified also by an item-id and driveId according this OneDrive GRAPH API documentation:

[content] => {"parentReference":{"driveId":"b!JhgH9inZ9kajgc2OJ***","id":"01Z3A2R***"}}
[method] => POST
[Content-Type] => application/json
[header] => Authorization: Bearer eyJ0eXA*****

With, or without the driveId field, it does not work. This is the URL:

https://graph.microsoft.com/v1.0/users/info@***/drive/items/01Z3A2RRVH5ZJ7ZIS**/copy

This are the current API settings: enter image description here

What am I doing wrong that I receive 400 Bad Request? All other requests, like iterating through the directories or even getting the content of a file work perfectly!


Solution

  • Content-Type has to be inside of header. My bad. Also, the driveId is not needed. This is the HTTP data, everything else remains the same.

    [content] => {"parentReference":{"id":"01Z3A2RRUT7ZDD*"}}
    [method] => POST
    [header] => Content-Type: application/json
                Authorization: Bearer eyJ0eXAiOiJ****