| author | spgraph-docs-team |
|---|---|
| title | driveItem: copy |
| ms.localizationpriority | medium |
| ms.subservice | sharepoint |
| description | Asynchronously creates a copy of an driveItem (including any children), under a new parent item or with a new name. |
| doc_type | apiPageType |
| ms.date | 03/14/2024 |
Namespace: microsoft.graph
Asynchronously creates a copy of an driveItem (including any children), under a new parent item or with a new name.
[!INCLUDE national-cloud-support]
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
[!INCLUDE permissions-table]
POST /drives/{driveId}/items/{itemId}/copy
POST /groups/{groupId}/drive/items/{itemId}/copy
POST /me/drive/items/{item-id}/copy
POST /sites/{siteId}/drive/items/{itemId}/copy
POST /users/{userId}/drive/items/{itemId}/copyThis method supports the @microsoft.graph.conflictBehavior query parameter to customize the behavior when a conflict occurs.
| Value | Description |
|---|---|
| fail | Default behavior is to report the failure. |
| replace | Overwrite existing item at the target site. |
| rename | Rename the item. |
Note: The conflictBehavior is not supported for OneDrive Consumer.
| Name | Description |
|---|---|
| Authorization | Bearer {token}. Required. Learn more about authentication and authorization. |
| Content-Type | application/json. Required. |
In the request body, provide a JSON object with the following parameters.
| Name | Value | Description |
|---|---|---|
| parentReference | ItemReference | Optional. Reference to the parent item the copy will be created in. |
| name | string | Optional. The new name for the copy. If this isn't provided, the same name will be used as the original. |
Note: The parentReference should include the driveId and id parameters for the target folder.
Returns details about how to monitor the progress of the copy, upon accepting the request.
This example copies a file identified by {item-id} into a folder identified with a driveId and id value.
The new copy of the file will be named contoso plan (copy).txt.
POST https://graph.microsoft.com/v1.0/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "6F7D00BF-FC4D-4E62-9769-6AEA81F3A21B",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
},
"name": "contoso plan (copy).txt"
}[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
[!INCLUDE sample-code] [!INCLUDE sdk-documentation]
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/4A3407B5-88FC-4504-8B21-0AABD3412717The value of the Location header provides a URL for a service that will return the current state of the copy operation.
You can use this information to determine when the copy has finished.
In many cases the copy action is performed asynchronously. The response from the API will only indicate that the copy operation was accepted or rejected; for example, due to the destination filename already being in use.