Deleting a file or folder

To delete a file or folder on Yandex Disk, specify the path to the resource that you want to delete. Keep in mind that moving resources to Trash doesn't increase available space on Yandex Disk. To free up space, you need to delete resources from Trash.

Request format

Use the DELETE method to send the delete request.

https://cloud-api.yandex.net/v1/disk/resources
 ? path=<path to the resource that you want to delete>
 & [permanently=<permanent deletion flag>]
 & [fields=<properties to include in the response>]
path*

The path to the resource being deleted. For example, $2Ffoo%2Fphoto.png.

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

permanently

Permanent deletion flag. Supported values:

  • false: the deleted file or folder is moved to Trash (used by default).
  • true: the file or folder is deleted without moving to Trash.
fields
List of JSON properties to include in the response. Keys not specified in this list are omitted when generating a response. If the parameter isn't specified, the response is returned in full without omitting anything.

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

* Required parameter.

Response format

If the request is processed without errors, the API creates the response body based 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, the relevant response code is returned, and the response body contains an error description.

File or empty folder

The API returns the 204 No content code (resource successfully deleted) without a response body.

Non-empty folder

Deleting a non-empty folder can take some time, so the API returns the 202 Accepted code (deletion started).

Apps must track the status of requested operations. The API returns a link to the status of the requested operation in the response body within the Link object.

Sample response:

{
  "href": "https://cloud-api.yandex.net/v1/disk/operations?id=d80c269ce4eb16c0207f0a15t4a31415313452f9e950cd9576f36b1146ee0e42",
  "method": "GET",
  "templated": false
}

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. To send a request to this address, replace the placeholder values in the curly brackets with the parameter values.
  • "false" — The URL can be requested without changes.