# Batch Delete Files

You can easily [delete](/help/file-management/delete-files/) 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](/help/rest-api/reference/).

Using an AI coding agent?

Install the [`sirv-api`](https://www.skills.sh/sirv/image-optimization-skill/sirv-api) skill, and your agent can call the Sirv API for you. Ask in plain words, such as “Upload the photos in /shoots/spring and tag them by product.” [See all 8 skills](/help/rest-api/sirv-skills-for-ai-agents/)

## 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](/help/rest-api/search-files-with-the-api/).

If deleting a folder, all its contents will be deleted, including its files and any subfolders, which lowers the [storage](/help/account-management/billing-plans/sirv-storage-calculation/) your account uses against its [allowance](/help/getting-started/allowances/).

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

1.  First, you should [connect to the Sirv API](/help/rest-api/reference/authentication/), to obtain a bearer token.
    
2.  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](/help/rest-api/reference/files/batch-delete/#delete-a-batch-of-files-or-directories) for examples in Python, Node.js, JavaScript, Java, PHP, Ruby, Swift, Go and C#):

```bash
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.

3.  If your request was successful, you will receive an ID in the response, such as this:

```js
{
  "id": "Gbycla6K12E2hx5H4ZGFqpNY681VKwbj"
}
```

4.  To check the progress of your request, submit the ID in a GET request, like so (example using Curl):

```bash
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%:

```js
{
  "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:

```js
{
  "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](/help/account-management/user-access-management/folder-lock/) 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

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

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:

```js
{
  "filenames": ["/Example/folder/", "/Products/19568269/19568269.mp4", "/Main_Folder/Sub-folder/SKU-abc123/My-product-name-abc123-01.jpg"]
}
```

## API testing tools

To test any of Sirv’s [REST API](/help/rest-api/sirv-rest-api/) commands, you might like to use Sirv’s [swagger.json URL](https://api.sirv.com/swagger.json) or add the [Sirv Postman API collection](https://www.postman.com/red-capsule-93818/workspace/sirv-api/collection/296061-358bdd21-10e7-4825-b82e-1229cb1865b4) for use in Postman, Firecamp and other API testing programs.
