## Restore file

`POST /v1/files/:id/restore`

Returns a file from the Bitrix24 trash to its folder. If the folder is in the trash too, restores it as well, together with all folders above it.

## 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 deleting |

No request body is sent.

## Examples

### curl — personal key

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

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/files/10745/restore" \
  -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/10745/restore', {
  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('Restored by this call:', body.meta.restored, 'name:', body.data.name)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/files/10745/restore', {
  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('Restored by this call:', body.meta.restored, 'name:', body.data.name)
```

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | `true` on success |
| `data` | object | The file after the call. All fields — see [File fields](/docs/entities/files/fields) |
| `data.name` | string | Current file name. If the folder already has a file with the same name, a number is appended to the name: `report.txt` becomes `report (1).txt` |
| `data.deletedType` | number | Deletion status: `0` — the file is not in the trash |
| `data.deletedAt` | string \| null | Time of the last deletion (ISO 8601). Restoring does not clear the field |
| `data.deletedBy` | number \| null | ID of the user who deleted the file. Restoring does not clear the field. List: `GET /v1/users` |
| `meta.restored` | boolean | `true` — the file was restored by this call. `false` — the file was not in the trash, and the call changed nothing |
| `meta.renamedFrom` | string \| null | File name before restoring, if it changed because of a name collision. `null` — the name is unchanged |

## Response example

```json
{
  "success": true,
  "data": {
    "id": 10745,
    "name": "report.txt",
    "code": null,
    "storageId": 1379,
    "type": "file",
    "folderId": 10739,
    "deletedType": 0,
    "globalContentVersion": 1,
    "fileId": 39249,
    "size": 33,
    "createdAt": "2026-10-15T18:25:17.000Z",
    "updatedAt": "2026-10-15T18:27:26.000Z",
    "deletedAt": "2026-10-15T18:26:24.000Z",
    "createdBy": 1295,
    "updatedBy": 1295,
    "deletedBy": 1295,
    "downloadUrl": "https://vibecode.bitrix24.com/v1/files/10745/download",
    "detailUrl": "https://<portal>.bitrix24.com/company/personal/user/1295/disk/file/Documents/report.txt"
  },
  "meta": {
    "restored": true,
    "renamedFrom": null
  }
}
```

## Error response example

404 — the file does not exist, including after 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 restoring 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 after [permanent deletion](/docs/entities/files/purge) |
| 422 | `DISK_RESTORE_REFUSED` | Bitrix24 did not confirm the restore. Re-read the file via [`GET /v1/files/:id`](/docs/entities/files/get) |
| 422 | `BITRIX_ERROR` | Bitrix24 refused to restore 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 restore was sent. The outcome is unknown and the request was not retried — re-read the file before calling the method again |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 was unavailable while the file was being read; the restore was not sent |

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

## Known specifics

**Neighboring objects stay in the trash.** Only the folders above the file come back from the trash together with it. Other files and folders in those folders stay in the trash — restore them with separate calls.

**Public link.** While the file is in the trash, its [public link](/docs/entities/files/public-link) does not open the file. After the file is restored, the previous link works again.

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

## See also

- [Delete file](/docs/entities/files/delete)
- [Permanently delete file](/docs/entities/files/purge)
- [Get file](/docs/entities/files/get)
- [Public link to a file](/docs/entities/files/public-link)
- [Files](/docs/entities/files)
