
## Delete message

`DELETE /v1/bots/:botId/messages/:messageId`

Deletes a message. By default, it performs a soft hide (the message is hidden but stays in the database). For full removal from the database, pass `complete: true`.

## Request fields (body)

| Parameter | Type | Required | Default | Description |
|----------|-----|:-----:|-----------|---------|
| `complete` | boolean | no | `false` | `true` — full removal from the DB, `false` — soft hide |

## Examples

### curl — personal key

```bash
curl -X DELETE https://vibecode.bitrix24.com/v1/bots/42/messages/1502 \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "complete": true }'
```

### curl — OAuth application

```bash
curl -X DELETE https://vibecode.bitrix24.com/v1/bots/42/messages/1502 \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "complete": true }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/messages/1502', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ complete: true }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/messages/1502', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ complete: true }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `data.result` | boolean | `true` on successful deletion |

## Response example

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

## Error response example

403 — the bot belongs to a different key:

```json
{
  "success": false,
  "error": {
    "code": "BOT_ACCESS_DENIED",
    "message": "This bot belongs to a different API key"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_BOT_ID` | `botId` is not a number |
| 404 | `BOT_NOT_FOUND` | No bot found with this ID |
| 403 | `BOT_ACCESS_DENIED` | The bot belongs to a different API key |
| 502 | `BITRIX_ERROR` | Bitrix24 error (error text in `message`) |
| 403 | `SCOPE_DENIED` | The API key does not have the `imbot` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |

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

## Known specifics

**Soft vs full deletion:** without `complete: true` the message is marked deleted but remains in the database. With `complete: true` it is removed entirely.

**System messages:** messages with `authorId = 0` (sent with `system: true`) cannot be deleted by the bot unless it is a chat administrator.

**Empty body:** for a soft delete the body can be omitted.

## See also

- [Send message](/docs/bots/messages/send)
- [Update message](/docs/bots/messages/update)
- [Bot platform](/docs/bots)
- [Limits and optimization](/docs/optimization)
