# Get a file access token

`POST https://api.chat-data.com/api/v2/get-sas-token`

Canonical: https://www.chat-data.com/api-reference/get-sas-token

## Authentication

Send an API key as a Bearer token: `Authorization: Bearer $CHAT_DATA_API_KEY`. Workspace keys reach every chatbot in the workspace; chatbot-scoped keys reach only their chatbot. Keep keys on the server.

## Description

Generate a read-only Shared Access Signature (SAS) token for accessing a specific uploaded file.

## Request body (`application/json`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| chatbotId | string | yes | The unique identifier allocated to the chatbot. |
| fileUrl | string | yes | The URL of the file to generate a SAS token for. |

## Example request

```bash
curl 'https://api.chat-data.com/api/v2/get-sas-token' \
  -H "Authorization: Bearer $CHAT_DATA_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "chatbotId": "6650f1c2a9e4b83d2c7a1f05",
  "fileUrl": "https://example.blob.core.windows.net/chatfiles/6650f1c2a9e4b83d2c7a1f05/product-handbook.pdf"
}'
```

## Example response (200)

```json
{
  "status": "success",
  "url": "https://example.blob.core.windows.net/chatfiles/6650f1c2a9e4b83d2c7a1f05/product-handbook.pdf?sv=2024-11-04&se=2026-11-13T09%3A30%3A00Z&sr=b&sp=r&sig=Xq7mB2v9KpL4tR8wN1cZ5yF3hJ6dS0aE%2BuG7iO2kQ%3D",
  "sasToken": "sv=2024-11-04&se=2026-11-13T09%3A30%3A00Z&sr=b&sp=r&sig=Xq7mB2v9KpL4tR8wN1cZ5yF3hJ6dS0aE%2BuG7iO2kQ%3D"
}
```

## Responses

| Status | Description |
| --- | --- |
| 200 | Successful response. For a file that does not exist, `sasToken` is empty and `url` ends with `?`. |
| 400 | `fileUrl` is missing, or it is not inside this chatbot's storage folder. |
| 401 | Authentication failed: the `Authorization` header is missing or not in the `Bearer <key>` format, the API key does not exist, its workspace is unavailable or has no owner, or the workspace's plan does not include API access. `message` says which. |
| 403 | The API key cannot access the requested chatbot. A chatbot-scoped key used with another chatbot's ID gets `Access denied to this chatbot`. A workspace key gets `Chatbot <id> was not found in this API key's workspace. It may have been deleted or moved to another workspace.` when the chatbot does not exist or belongs to another workspace. |
| 404 | `chatbotId` was not provided. |
| 429 | The workspace sent more than 600 API requests in the last minute. Wait the number of seconds given in the `Retry-After` header (and in `message`) before retrying. |
