## Public link to a file

`POST /v1/files/:id/public-link`

Creates a public link to a file or returns the existing one: anyone who has the link can open the file without signing in to Bitrix24. The link cannot be revoked via the API.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `id` (path) | number | yes | File ID. List: `GET /v1/files?folderId=X` |

No request body is sent.

## Examples

### curl — personal key

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

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/files/10745/public-link" \
  -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/public-link', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})
const body = await res.json()
if (!body.success) throw new Error(body.error.code)
const link = body.data.url
console.log('Link received, file in trash:', body.meta.inTrash)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/files/10745/public-link', {
  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)
const link = body.data.url
console.log('Link received, file in trash:', body.meta.inTrash)
```

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | `true` on success |
| `data.url` | string | Public link to the file. Opens the file without authorization |
| `data.revocableViaApi` | boolean | Always `false`: the link cannot be revoked via the API |
| `meta.inTrash` | boolean | `true` — the file is in the trash. The link is issued but opens the file only after [restoration](/docs/entities/files/restore) |

## Response example

```json
{
  "success": true,
  "data": {
    "url": "https://bitrix24public.com/<portal>.bitrix24.com/file/EXAMPLE_TOKEN",
    "revocableViaApi": false
  },
  "meta": {
    "inTrash": false
  }
}
```

## Error response example

404 — the file does not exist:

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

## 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 creating a link changes portal data |
| 403 | `DISK_PUBLIC_LINK_PLAN_UNAVAILABLE` | Public links to files are not available on the portal's plan |
| 403 | `BITRIX_ACCESS_DENIED` | The key owner has no permission to modify the file, or public links are disabled on the portal. The response does not distinguish these causes |
| 404 | `ENTITY_NOT_FOUND` | No file with this `id` |
| 422 | `DISK_PUBLIC_LINK_REFUSED` | Bitrix24 did not return a link |
| 422 | `BITRIX_ERROR` | Bitrix24 refused to create the link; 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 link was requested. The outcome is unknown and the request was not retried. A repeated call returns the same link if it was created |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 was unavailable while the file was being read; the link was not requested |

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

## Known specifics

**The link is an access secret.** The response comes with the `Cache-Control: private, no-store` header. Do not write `data.url` to logs, audit records or telemetry.

**Existing link.** If the file already has a public link, the call returns it instead of creating a new one. It may be a link created by another employee, including one with a password or an expiration date: the response does not say whether the link is protected.

**Trash and deletion.** While the file is in the trash, the link does not open it; after restoration, the link opens it again. Via the API, the only way to disable the link is to [permanently delete the file](/docs/entities/files/purge).

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

## See also

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