For AI agents: markdown of this page — /docs-content-en/chats/messages/delete.md documentation index — /llms.txt

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
ParameterdialogId (path) Typestring Requiredyes DescriptionDialog identifier: numeric user ID or chatXXX for group chats. chatXXX is the id field of a recent dialogs row; a user ID comes from the user list
ParametermessageId (path) Typenumber Requiredyes DescriptionMessage ID — from the send response or the id field of a message in the chat feed
Parameterformat (query) Typestring Requiredno Descriptionv2 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

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

curl — OAuth application

Terminal
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

Terminal
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
Fieldsuccess Typeboolean DescriptionAlways true on success
Fielddata Typeboolean Descriptiontrue on successful deletion
Fielddata.result Typeboolean DescriptionThe 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
HTTP400 CodeINVALID_PARAMS DescriptionmessageId is not a positive integer — checked before the Bitrix24 call
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 returned an error — the message was not found or is unavailable (details in message). The portal code is in error.b24Code
HTTP400 CodeINVALID_PARAMS DescriptionThe v2 mode only: a body field or a query parameter other than format
HTTP404 CodeENTITY_NOT_FOUND DescriptionThe 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
HTTP403 CodeWRITE_BLOCKED_READONLY_KEY DescriptionThe key is read-only — see access rights
HTTP403 CodeSCOPE_DENIED DescriptionThe key does not have the im scope
HTTP401 CodeTOKEN_MISSING DescriptionThe key has no configured tokens
HTTP502 CodeME_ALIAS_RESOLUTION_FAILED DescriptionThe v2 mode only: failed to resolve the user for the me alias

The full list of common API errors — 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