Copying a driveitem allows for defining @microsoft.graph.conflictBehavior to handle conflicts, as per design according to issue #759
This should also be documented.
Conflicts cause 409 Conflict response despite @microsoft.graph.conflictBehavior.
{
"error": {
"code": "nameAlreadyExists",
"message": "The specified item name already exists.",
"innerError": {
"request-id": "{requestId}",
"date": "{date}"
}
}
}
POST https://graph.microsoft.com/v1.0/users/{username}/drive/items/{itemId}/copy
{
"parentReference": {
"driveId": "{driveId}",
"id": "{parentItemId}"
},
"name": "foo",
"@microsoft.graph.conflictBehavior": "rename"
}
^ Making this request twice will cause 409 Conflict nameAlreadyExists on the second try.
I'm trying this aswell using the Graph API and it always returns nameAlreadyExists regardless of the behaviorConflict specified
{
"parentReference": {
"driveId": "{driveId}",
"id": "{parentItemId}"
},
"name": "test",
"@microsoft.graph.conflictBehavior": "rename"
}
How to work around this ??
any updates?
come on guys?
I can also confirm that this still does not function properly.
Adding @microsoft.graph.conflictBehavior=rename to query string parameters did work for me
as @marcogiannetta said, you have to add to the query params.
Example:
https://graph.microsoft.com/v1.0/me/drive/items/{your-file-id}/[email protected]=rename
If you're using the C# Graph SDK you have to send a query option on the request.
List<QueryOption> options = new List<QueryOption>
{
new QueryOption("@microsoft.graph.conflictBehavior", "rename")
};
Well docs should be updated then
It looks like the workaround above only works for OneDrive for Business... OneDrive Personal still seems to ignore it.
Adding @microsoft.graph.conflictBehavior to query string doesn't work either:
https://graph.microsoft.com/v1.0/me/drive/items/{your-file-id}/[email protected]=replace
Edit: It actually works, my bad. I just had different unrelated error (overwrite is not supported for folders)
Most helpful comment
Adding @microsoft.graph.conflictBehavior=rename to query string parameters did work for me