## Permanently delete file

`POST /v1/files/:id/purge`

Deletes a file irreversibly, bypassing the Bitrix24 trash: the method accepts both a file in a folder and a file that is already in the trash. To be able to bring the file back, move it to the trash instead.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `id` (path) | number | yes | File ID. List: `GET /v1/files?folderId=X`. Trashed files do not appear in the list — save the `id` before moving the file to the trash |

No request body is sent.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/files/10751/purge" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/files/10751/purge" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/files/10751/purge', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})
const body = await res.json()
if (!body.success) throw new Error(body.error.code)
console.log('File permanently deleted:', body.data.id)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/files/10751/purge', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})
const body = await res.json()
if (!body.success) throw new Error(body.error.code)
console.log('File permanently deleted:', body.data.id)
```

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | `true` — the file is permanently deleted |
| `data.id` | number | ID of the deleted file |
| `data.purged` | boolean | Always `true` |

## Response example

```json
{
  "success": true,
  "data": {
    "id": 10751,
    "purged": true
  }
}
```

## Error response example

404 — the file does not exist, including on a repeated permanent deletion:

```json
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "Could not find entity with id '10751'."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_ID` | `id` is not a positive integer |
| 401 | `TOKEN_MISSING` | The key's portal has no authorization tokens |
| 403 | `SCOPE_DENIED` | The key lacks the `disk` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode, and deletion changes portal data |
| 403 | `BITRIX_ACCESS_DENIED` | The key owner has no permissions on the file in Bitrix24 |
| 404 | `ENTITY_NOT_FOUND` | No file with this `id`, including on a repeated permanent deletion |
| 422 | `DISK_DELETE_REFUSED` | Bitrix24 refused to delete the file: the file is locked or protected |
| 422 | `BITRIX_ERROR` | Bitrix24 refused to delete the file; the reason is in `message` |
| 429 | `RATE_LIMITED` | Rate limit exceeded — wait 1-2 seconds and retry |
| 502 | `DISK_OUTCOME_UNKNOWN` | The connection to Bitrix24 dropped after the deletion was sent. The outcome is unknown and the request was not retried. Re-read the file via [`GET /v1/files/:id`](/docs/entities/files/get): a `404` response means the file is deleted |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 was unavailable while the file was being read; the deletion was not sent |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

**What is deleted along with the file.** All versions of the file, its public link, attachments of this file in tasks, chats, CRM fields and comments, and links to the file in other storages.

**Batch calls.** Permanent deletion is not part of [`POST /v1/batch`](/docs/batch) — call it as a separate request.

## See also

- [Delete file](/docs/entities/files/delete)
- [Restore file](/docs/entities/files/restore)
- [Get file](/docs/entities/files/get)
- [Files](/docs/entities/files)
