Moving a file or folder

To move files and folders on Yandex.Disk, specify the current path to the resource and its new location.

Request format

Use the POST method to send the move request.

https://cloud-api.yandex.net/v1/disk/resources/move
 ? from=<path to the resource to move>
 & path=<path to the moved resource>
 & [overwrite=<overwriting flag>]
 & [fields=<properties to include in the response>]
Query parameters
from *

The path to the resource to move. For example, %2Ffoo%2Fphoto.png.

The path in the parameter value should be URL-encoded.

path *

The path to the new location of the resource. For example, %2Fbar%2Fphoto.png (the new resource path can be up to 32760 characters long).

The path in the parameter value should be URL-encoded.

overwrite

Whether to overwrite files. It is used if the resource is moved to a folder that already contains a resource with the same name.

Acceptable values:

  • false — Cancel moving and don't overwrite the files. Used by default.
  • true — Move the resource and remove existing files with the same name.
fields

List of JSON keys to include in the response. Keys that are not included in this list will be discarded when forming the response. If the parameter is omitted, the response is returned in full, without discarding anything.

Key names should be comma-separated, and embedded keys should be separated by dots. For example: name, _embedded. items. path.

*  Required

Response format

If the request was processed without errors, the API composes the response body depending on the type of the specified resource. The response for an empty folder or file is different from the response for a non-empty folder. (If the request caused an error, a relevant response code is returned, with the response body featuring the error description.)

File or empty folder

The API responds with the 201 Created code (the resource was successfully moved) and returns a link to the metainformation about the created resource in the response body, in the Link object.

Sample response:

{
  "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png",
  "method": "GET",
  "templated": false
}

Non-empty folder

Moving a non-empty folder can take an unknown amount of time, so the API responds with the code 202 Accepted (the folder moving process has started).

Applications must track the status of requested operations. The Yandex.Disk API returns the link to the status of the operation started by the request. The link is included in the Link object in the response body.

Sample response:

{  "href": "https://cloud-api.yandex.net/v1/disk/operations?id=33ca7d03ab21ct41b4a40182e78d828a3f8b72cdb5f4c0e94cc4b1449a63a2fe",  "method": "GET",  "templated": false}
Response elements
Element Description
href

URL. It may be a URL template; see the templated key.

method

The HTTP method for requesting the URL from the href key.

templated

Indicates a URL template according to RFC 6570. Possible values:

  • “true” — URL template. Before sending a request to this address, put the desired parameter values in place of the values in curly brackets.
  • “false” — The URL can be requested without changes.