## Discard an uploaded file

`POST /v1/chats/:chatId/files/uploads/discard`

Asks Bitrix24 to delete a file from the chat folder. The `true` or `false` answer is preserved: the client decides whether it can treat the file as removed.

## Parameters

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `chatId` (path) | number | yes | Chat ID |
| `fileId` (body) | number | yes | Positive file ID |

Requires the `im` scope and a write-enabled key. Other fields and query parameters are rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
curl -X POST https://vibecode.bitrix24.com/v1/chats/42/files/uploads/discard \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"fileId":7701}'
```

### curl — OAuth application

```bash
curl -X POST https://vibecode.bitrix24.com/v1/chats/42/files/uploads/discard \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"fileId":7701}'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/42/files/uploads/discard', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"fileId": 7701}),
})
const { success, data, error } = await res.json()
console.log(success ? data : error)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/42/files/uploads/discard', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"fileId": 7701}),
})
const { success, data, error } = await res.json()
console.log(success ? data : error)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on success |
| `data` | boolean | The Bitrix24 `true` or `false` value, unchanged |

## Response example

```json
{
  "success": true,
  "data": true
}
```

## Error response example

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "`fileId` must be a positive integer."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS`, `INVALID_CHAT_ID` | Invalid IDs or unexpected parameters |
| 401 | `TOKEN_MISSING` | No Bitrix24 access tokens |
| 403 | `SCOPE_DENIED`, `WRITE_BLOCKED_READONLY_KEY`, `BITRIX_ACCESS_DENIED` | Missing scope, write permission, or Bitrix24 access |
| 404 | `ENTITY_NOT_FOUND` | File or chat not found |
| 422 | `BITRIX_ERROR` | Other Bitrix24 refusal |
| 429 | `QUEUE_TIMEOUT` | Bitrix24 request queue is busy |

`false` remains a successful response and differs from a refusal. A named Bitrix24 refusal can map to `400`, `403`, or `404`; `error.b24Code` is not guaranteed. The platform does not retry after an unknown outcome.

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

## See also

- [Upload to folder](/docs/chats/files/upload-to-folder)
- [Check existence](/docs/chats/files/upload-status)
- [Publish files](/docs/chats/files/upload-publish)
- [Chat files](/docs/chats/files)
