Batch Delete Files
Short answer
The batch delete API removes up to 1,000 files or folders in one request, and deleting a folder also deletes everything in it. Get a bearer token, then send a POST request to /v2/files/batch/delete with the list of paths. Enterprise accounts can send 25 requests an hour, Business 100+ 10, and Business 5.
After reading this you will know
- How to delete many files or folders in one API request
- The hourly and per-request limits for each plan
- Tools for testing the request
You can easily delete thousands of files or folders with the batch delete API. The batch delete API command is one of more than 60 commands in the Sirv REST API.
About the delete API
Section titled “About the delete API”You can delete up to 1000 paths per API request. Each path could be a file or folder, for example from an API search.
If deleting a folder, all its contents will be deleted, including its files and any subfolders, which lowers the storage your account uses against its allowance.
If you need to delete more than 1000 paths, submit multiple requests with up to 1000 in each one.
The API endpoint is https://api.sirv.com/v2/files/batch/delete and usage instructions are below.
How to delete multiple files or folders
Section titled “How to delete multiple files or folders”-
First, you should connect to the Sirv API, to obtain a bearer token.
-
Once you have a bearer token (looks like this but longer:
eyJhcIUiI...bGllbb2YQ.wVDr3KMIWhx1bEknCD-r4), you can submit a batch delete API request.
The following example uses Curl (visit the batch delete API docs for examples in Python, Node.js, JavaScript, Java, PHP, Ruby, Swift, Go and C#):
curl --request POST \ --url https://api.sirv.com/v2/files/batch/delete \ --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiI...bGllbnRb2YifQ.wVDr3KMBHIyD5i98emWhx1bEfN3xknCD-r4' \ --header 'Content-Type: application/json' \ --data '{ "filenames": ["/Example_folder", "/my-file.jpg", "/Here is a/Sub-Folder"]}'Each filename should start with a slash / representing the root of your Sirv account. Each filename should be wrapped in quotation marks " " and separated with a comma , character.
- If your request was successful, you will receive an ID in the response, such as this:
{ "id": "Gbycla6K12E2hx5H4ZGFqpNY681VKwbj"}- To check the progress of your request, submit the ID in a GET request, like so (example using Curl):
curl --request GET \ --url 'https://api.sirv.com/v2/files/batch/delete?id=Gbycla6K12E2hx5H4ZGFqpNY681VKwbj' \ --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiI...bGllbnRb2YifQ.wVDr3KMBHIyD5i98emWhx1bEfN3xknCD-r4' \ --header 'Content-Type: application/json'You will see the progress completed percentage e.g. 30%:
{ "progress": 30}It can take 10 seconds to delete 1000 files. It can take minutes to delete huge numbers of files.
Once deletion has completed, the response progress will show 100%, like so:
{ "progress": 100, "result": { "skipped": [], "notfound": 0, "deleted": { files: 2482, dirs: 172 } } }}The result will also show how many files and folders (dirs) were deleted.
If any files or folders had been locked from editing, they will be skipped and shown in the skipped section. They will be listed in an array, with opening and closing [] square brackets.
It will be empty if no files were skipped.
Any files/folders that didn’t exist will be counted in the notfound section.
A common cause for files not found is the wrong folder path - keep in mind that all paths should start with a leading / slash.
Limits
Section titled “Limits”Batch deletion requests are limited in the following ways:
| Enterprise | Business 100+ | Business | Trial | Free | |
|---|---|---|---|---|---|
| Requests per hour | 25 | 10 | 5 | None | None |
| Paths per request | 1000 files or folders | 1000 files or folders | 1000 files or folders | - | - |
| Size of body | 32 KB | 32 KB | 32 KB | - | - |
How to handle limits
Section titled “How to handle limits”A response will be returned to each of your API requests. Successful requests will receive a 200 response status, otherwise you will receive an error such as 413, 429, 400.
The body of your request is the data section, containing the list of paths to be deleted.
The maximum size of 32 KB is equal to 32,768 characters, which is a large number but your request will exceed this if, for example, you try to delete 1000 files with an average path longer than 29 characters.
3 additional characters are used for separating each path.
If your request exceeds 32 KB, you will receive a 413 error response “Request Entity Too Large”.
To avoid hitting the 32 KB body limit, delete a smaller number of files at a time e.g. 200 or 300.
Alternatively, you could count the number of characters in your list of files and submit requests with fewer than 32,768 characters in the body.
The following list of files contains 141 characters, including spaces. It will delete 1 folder and 2 files:
{ "filenames": ["/Example/folder/", "/Products/19568269/19568269.mp4", "/Main_Folder/Sub-folder/SKU-abc123/My-product-name-abc123-01.jpg"]}API testing tools
Section titled “API testing tools”To test any of Sirv’s REST API commands, you might like to use Sirv’s swagger.json URL or add the Sirv Postman API collection for use in Postman, Firecamp and other API testing programs.
