> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chamelio.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Download File

> Download a file stored in Chamelio Knowledge Center by its unique file ID using an OAuth access token that carries the files:read scope.

## Endpoint

```
GET /v2/files/{file_id}
```

## Authentication

This endpoint requires an OAuth access token. Send it as a bearer token:

```bash theme={null}
Authorization: Bearer your_access_token
```

**Required scope:** `files:read`

## Path Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `file_id` | string | Yes | Unique file identifier (format: `document_{id}` or `attachment_{id}`) |

## Request Example

```bash cURL theme={null}
curl -X GET "https://platform.chamelio.ai/v2/files/document_789" \
  -H "Authorization: Bearer your_access_token"
```

```python Python theme={null}
import requests

file_id = "document_789"

url = f"https://platform.chamelio.ai/v2/files/{file_id}"
headers = {
    "Authorization": "Bearer your_access_token"
}

response = requests.get(url, headers=headers)
print(response.json())
```

```javascript JavaScript theme={null}
const fileId = 'document_789';

const response = await fetch(
  `https://platform.chamelio.ai/v2/files/${fileId}`,
  {
    method: 'GET',
    headers: {
      'Authorization': 'Bearer your_access_token'
    }
  }
);

const data = await response.json();
console.log(data);
```

> [!NOTE]
>
> There is no `user_email` query parameter here. The download is attributed to the access token's user
> automatically.

## Response

### Success Response

**Status Code:** `200 OK`

```json theme={null}
{
  "file_id": "document_789",
  "file_name": "acme_contract.pdf",
  "content_type": "application/pdf",
  "download_url": "https://s3.amazonaws.com/chamelio-files/...",
  "expires_at": "2025-01-20T12:00:00Z"
}
```

### Response Fields

| Field | Type | Description |
| - | - | - |
| `file_id` | string | The file identifier that was requested |
| `file_name` | string | Name of the file |
| `content_type` | string | MIME type of the file (e.g., `application/pdf`, `application/vnd.openxmlformats-officedocument.wordprocessingml.document`) |
| `download_url` | string | Presigned URL to download the file |
| `expires_at` | string | ISO 8601 timestamp when the download URL expires |

## Error Responses

### 400 Bad Request

Returned when the file ID format is invalid, or when the access token has no user behind it.
`client_credentials` tokens act as the admin who created the application, so this applies only to
tokens issued before application creators were recorded.

```json theme={null}
{
  "detail": "Invalid file ID format. Expected document_{id} or attachment_{id}"
}
```

```json theme={null}
{
  "detail": "client_credentials tokens are not associated with a user"
}
```

### 401 Unauthorized

Returned when the access token is missing, unknown, revoked, or expired, or when an `X-API-Key` was
sent instead of a bearer token. See [OAuth error responses](https://docs.chamelio.ai/api-reference/oauth-apps.md#error-responses).

```json theme={null}
{
  "detail": "Invalid access token"
}
```

### 403 Forbidden

Returned when the token does not carry the required scope.

```json theme={null}
{
  "detail": "Insufficient scope; this endpoint requires: files:read"
}
```

### 404 Not Found

Returned when the file does not exist.

```json theme={null}
{
  "detail": "Not found"
}
```

### 429 Too Many Requests

Returned when your organization exceeds its per-minute request limit.

```json theme={null}
{
  "detail": "Rate limit exceeded"
}
```

### 500 Internal Server Error

Returned when the request fails due to a server error.

```json theme={null}
{
  "detail": "Failed to download file"
}
```

## Notes

> [!WARNING]
>
> Grant the `files:read` scope only to applications that need to download files. To confirm which files it covers for your integration, ask your Chamelio legal engineer.

> [!NOTE]
>
> File IDs follow a specific format: `document_{id}` for documents and `attachment_{id}` for attachments.
> Use the complete file ID as returned from other endpoints.

> [!WARNING]
>
> The presigned download URL expires after a certain time (indicated by `expires_at`). Download the file
> before the URL expires or request a new URL.

## Common MIME Types

| Extension | MIME Type |
| - | - |
| `.pdf` | `application/pdf` |
| `.docx` | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` |
| `.doc` | `application/msword` |
| `.xlsx` | `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet` |
| `.txt` | `text/plain` |
| `.png` | `image/png` |
| `.jpg`, `.jpeg` | `image/jpeg` |

## Use Cases

This endpoint is useful for:

* **File retrieval** - Download files uploaded to or generated by workflows
* **Document export** - Export documents to external systems
* **Archival** - Save files to long-term storage
* **User downloads** - Allow end users to download files through custom interfaces
