
## Download file

`GET /v1/bots/:botId/files/:fileId`

Returns a download link for a file from a chat with the bot. The file ID comes in the message event and in the file upload response.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `botId` (path) | number | yes | Bot ID |
| `fileId` (path) | number | yes | File ID |

## Examples

### curl — personal key

```bash
curl https://vibecode.bitrix24.com/v1/bots/42/files/789 \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl https://vibecode.bitrix24.com/v1/bots/42/files/789 \
  -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/bots/42/files/789', {
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})

const { success, data } = await res.json()
console.log('Download URL:', data.downloadUrl)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/files/789', {
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

const { success, data } = await res.json()
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | object | File link |
| `data.downloadUrl` | string | Download link for the file. The file name, size, and type are returned in the [Upload file](/docs/bots/files/upload) response |

## Response example

```json
{
  "success": true,
  "data": {
    "downloadUrl": "https://portal.bitrix24.com/rest/1/abc123/download/?token=imbot%7CaWQ9Nzg5..."
  }
}
```

## Error response example

404 — bot not found:

```json
{
  "success": false,
  "error": {
    "code": "BOT_NOT_FOUND",
    "message": "Bot 999 not found. Register it first via POST /v1/bots."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_BOT_ID` | `botId` is not a number |
| 400 | `INVALID_PARAMS` | `fileId` in the path must be a positive integer from `1` to `9007199254740991`, without a sign, leading zeros, fraction, exponent or whitespace. Rejected before calling Bitrix24 |
| 404 | `BOT_NOT_FOUND` | No bot found with this ID |
| 403 | `BOT_ACCESS_DENIED` | Bot belongs to a different API key |
| 422 | `BITRIX_ERROR` | Bitrix24 error (error text in `message`) |
| 403 | `SCOPE_DENIED` | API key does not have the `imbot` scope |
| 410 | `BOT_DISABLED` | The bot is disabled and does not process API calls. How to restore it — [Bot disabled](/docs/bots/troubleshooting#bot-disabled-bot_disabled) |
| 401 | `TOKEN_MISSING` | API key has no configured tokens |

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

## See also

- [Upload file](/docs/bots/files/upload)
- [Send message](/docs/bots/messages/send)
- [Bot platform](/docs/bots)
- [Limits and optimization](/docs/optimization)
