driveItem: move

Namespace: microsoft.graph

Important

APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.

Move a driveItem to a new parent.

To move a driveItem to a new parent item, your app requests an update to the parentReference of the driveItem to move. The move is a special type of Update operation. Your app can combine moving an item to a new container and updating other properties of the item into a single request.

When a driveItem is moved within the same site or container, all existing sharing links continue to work. If the driveItem is moved to a different site or container, existing sharing links no longer work.

This API is available in the following national cloud deployments.

Global service US Government L4 US Government L5 (DOD) China operated by 21Vianet

Permissions

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.

Permission type Least privileged permissions Higher privileged permissions
Delegated (work or school account) Files.ReadWrite Files.ReadWrite.All, Sites.ReadWrite.All
Delegated (personal Microsoft account) Files.ReadWrite Files.ReadWrite.All
Application Files.ReadWrite.All Sites.ReadWrite.All

HTTP request

PATCH /drives/{drive-id}/items/{item-id}
PATCH /groups/{group-id}/drive/items/{item-id}
PATCH /me/drive/items/{item-id}
PATCH /sites/{site-id}/drive/items/{item-id}
PATCH /users/{user-id}/drive/items/{item-id}

Request headers

Name Type Description
Authorization Bearer {token}. Required. Learn more about authentication and authorization.
if-match String If this request header is included and the eTag (or cTag) provided doesn't match the current eTag on the folder, a 412 Precondition Failed response is returned. Optional.

Request body

In the request body, supply the new value for the parentReference property. Existing properties that aren't included in the request body maintain their previous values or the properties are recalculated based on changes to other property values. For optimal performance, include only the values that change and omit the unchanged ones.

Note

When items are moved to the root of a drive, your application must use the actual ID of the root folder as the parent reference instead of the "id: root" syntax.

Response

If successful, this method returns a 200 OK response code and an updated driveItem resource in the response body.

For information about how errors are returned, see Error responses.

Examples

Request

The following example moves an item specified by {item-id} into a folder in the user's drive with the ID new-parent-folder-id.

PATCH https://graph.microsoft.com/beta/me/drive/items/{item-id}
Content-type: application/json

{
  "parentReference": {
    "id": "new-parent-folder-id"
  },
  "name": "new-item-name.txt"
}

Response

The following example shows the response for this move request.

HTTP/1.1 200 OK
Content-type: application/json

{
  "id": "0123456789abc",
  "name": "new-item-name.txt",
  "parentReference":
  {
    "driveId": "11231001",
    "path": "/drive/root:/Documents",
    "id": "1231203102!1011"
  }
}