Restoring a file or folder from the Trash

You can restore a resource that you moved to the Trash. To return it to the previous location, enter the path to it in the Trash. You can rename the restored resource.

If the file was located in a folder that doesn't exist at the moment, this folder is created in the same location. For example, if the disk is empty, and you restore a file that previously was in the /foo/bar/ folder, the folders foo and bar will be created.

Request format

Use the PUT method to send the request to restore a file or folder.

https://cloud-api.yandex.net/v1/disk/trash/resources/restore
 ? path=<path to the resource>
 & [name=<the new name of the resource>]
 & [overwrite=<overwriting flag>]
path *

The path to the resource from the Trash root directory. For example, %2Fbar%2Fphoto.png.

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

name

The new name of the resource being restored. For example, selfie.png.

overwrite

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

Acceptable values:

  • false — Don't overwrite the files and cancel restoring. Used by default.
  • true — Restore the resource and delete the files with the same name.
path *

The path to the resource from the Trash root directory. For example, %2Fbar%2Fphoto.png.

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

name

The new name of the resource being restored. For example, selfie.png.

overwrite

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

Acceptable values:

  • false — Don't overwrite the files and cancel restoring. Used by default.
  • true — Restore the resource and delete the files with the same name.

* Required

Response format

Restoring a resource from the Trash may take some time. Depending on the operation status, the Yandex.Disk server returns one of two responses:

  • If the request was process successfully, the API responds with the 201 Created code (the resource was successfully restored) and returns the link to metainformation about the created resource in the Link object in the response body.

    Sample response:

    {
      "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fselfie.png",
      "method": "GET",
      "templated": false
    }
  • If the save operation was started but has not yet finished, Yandex.Disk responds with the code 202 Accepted.

    Applications must track the status of requested operations. Yandex.Disk returns the link to the status of the operation launched 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/resources?path=disk%3A%2F%D0%97%D0%B0%D0%B3%D1%80%D1%83%D0%B7%D0%BA%D0%B8%photo.png",
      "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.
    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.

If the request caused an error, a relevant response code is returned, with the response body featuring the error description.