
## 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 | Required | Description |
|----------|-----|:-----:|---------|
| `dialogId` (path) | string | yes | Dialog identifier: numeric user ID or `chatXXX` for group chats. `chatXXX` is the `id` field of a [recent dialogs](/docs/chats/discovery/recent) row; a user ID comes from the [user list](/docs/entities/users/list) |
| `messageId` (path) | number | yes | Message ID — from the [send](/docs/chats/messages/send) response or the `id` field of a message in the [chat feed](/docs/chats/messages/list) |
| `format` (query) | string | no | `v2` turns on the v2 mode — see "The v2 mode" below. Any other value is ignored and the response is unchanged. A repeated `format` is not rejected: with `format=v1&format=v2` the last value wins, so the v2 mode is on, while `format=v2&format=v1` returns the legacy response. The bracket form `format[]=v2` turns on the v2 mode when all its values are `v2` |

**The v2 mode.** `format=v2` deletes the message. `data` carries `{ "result": true }` instead of `true`. The mode accepts no body fields and no query parameters other than `format`: anything extra is rejected with `400 INVALID_PARAMS` rather than forwarded to the Bitrix24 account. The message must belong to the dialog in the path: after the input checks, the platform reads that dialog without joining the chat and, if the message is not there, returns `404 ENTITY_NOT_FOUND` and deletes nothing. The `me` alias is resolved before this check. The regular mode does not check `dialogId`.

## 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()
```

### curl — the v2 mode

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | boolean | `true` on successful deletion |
| `data.result` | boolean | The v2 mode: `true` on successful deletion |

## Response example

The regular mode:

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

The v2 mode — `format=v2`:

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

## Error response example

422 — the message was not found, the time to modify it has expired, or you have no access:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Time has expired for modification or you don't have access",
    "b24Code": "CANT_EDIT_MESSAGE"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | `messageId` is not a positive integer — checked before the Bitrix24 call |
| 422 | `BITRIX_ERROR` | Bitrix24 returned an error — the message was not found or is unavailable (details in `message`). The portal code is in `error.b24Code` |
| 400 | `INVALID_PARAMS` | The v2 mode only: a body field or a query parameter other than `format` |
| 404 | `ENTITY_NOT_FOUND` | The v2 mode only: the message is not in the dialog in the path (it belongs to another dialog or does not exist) — nothing is deleted |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — see [access rights](/docs/access-rights) |
| 403 | `SCOPE_DENIED` | The key does not have the `im` scope |
| 401 | `TOKEN_MISSING` | The key has no configured tokens |
| 502 | `ME_ALIAS_RESOLUTION_FAILED` | The v2 mode only: failed to resolve the user for the `me` alias |

The 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)
