
## Delete a message

`DELETE /v1/chats/:dialogId/messages/:messageId`

Deletes a message from a dialog. A deleted message cannot be restored via the API — create a new one if needed.

## Parameters

| Parameter | Type | Req. | Description |
|----------|-----|:-----:|---------|
| `dialogId` (path) | string | yes | Dialog identifier: numeric user ID or `chatXXX` for group chats |
| `messageId` (path) | number | yes | Message ID (from the `POST /v1/chats/:dialogId/messages` response) |

## Examples

### curl — personal key

```bash
curl -X DELETE https://vibecode.bitrix24.com/v1/chats/42/messages/36889 \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl -X DELETE https://vibecode.bitrix24.com/v1/chats/42/messages/36889 \
  -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/chats/42/messages/36889', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/42/messages/36889', {
  method: 'DELETE',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | boolean | `true` on successful deletion |

## Response example

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

## Error response example

422 — Bitrix24 returned an error (message not found):

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Message not found"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 422 | `BITRIX_ERROR` | Bitrix24 returned an error — the message was not found or is unavailable (details in `message`) |
| 403 | `SCOPE_DENIED` | The key does not have the `im` scope |
| 401 | `TOKEN_MISSING` | The key has no configured tokens |

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

## Known specifics

**System messages.** Messages sent with `system: true` have `authorId = 0`. Such a message can only be deleted if you have chat administrator rights.

## See also

- [Messages](/docs/chats/messages)
- [Send a message](/docs/chats/messages/send)
- [Edit a message](/docs/chats/messages/update)
- [Read messages](/docs/chats/messages/list)
