## Remove a block from a message

`DELETE /v1/chats/messages/:messageId/blocks/:blockId`

Removes a block from a constructor message.

## Parameters

| Parameter | Type | Required | Default | Description |
|----------|-----|:-----:|-----------|---------|
| `messageId` (path) | number | yes | — | ID of the constructor message, a positive integer — `data.id` of the [v2 send](/docs/chats/messages/send) response or the `id` of a message with a non-null `block` in [Messages around a message](/docs/chats/messages/context) |
| `blockId` (path) | string | yes | — | Block ID — the value of `block.elements[].id` of the message. To get the message blocks, see [Messages around a message](/docs/chats/messages/context) |

No body is needed. Query parameters and body fields are rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
curl -X DELETE "https://vibecode.bitrix24.com/v1/chats/messages/1001/blocks/650a1b2c3d4e5" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

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

const { data } = await res.json()
console.log('Block removed:', data.result)
```

### JavaScript — OAuth application

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

const { data } = await res.json()
console.log('Block removed:', data.result)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data.result` | boolean | `true` — the block was removed |

## Response example

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

## Error response example

422 — the message has one block left:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "EMPTY_ELEMENTS",
    "b24Code": "EMPTY_ELEMENTS"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | `messageId` is not a positive integer, the body is not a JSON object, or a query parameter or body field is passed. Checked before any call to Bitrix24 |
| 404 | `ENTITY_NOT_FOUND` | Bitrix24 returned a generic "not found" code or an error with the text "not found". The portal code is in `error.b24Code` |
| 422 | `BITRIX_ERROR` | Bitrix24 returned an error, the portal code is in `error.b24Code`. `MESSAGE_NOT_FOUND` — there is no message with this ID, `BLOCK_NOT_FOUND` — the message has no blocks, `ELEMENT_NOT_FOUND` — there is no block with this ID, `EMPTY_ELEMENTS` — the block is the last one in the message, `MESSAGE_ACCESS_DENIED` — you have no permission to edit the message, for example it belongs to someone else |
| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — see [access rights](/docs/access-rights) |
| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |

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

## Known specifics

**Only constructor messages have blocks.** A message becomes a constructor message when it is sent with the `block` field in [v2 send mode](/docs/chats/messages/send) or when blocks are set on it by [editing the message](/docs/chats/messages/update) in v2 mode. A plain message has no blocks.

## See also

- [Add a block to a message](/docs/chats/messages/blocks-create)
- [Replace a block of a message](/docs/chats/messages/blocks-update)
- [Messages around a message](/docs/chats/messages/context)
- [Edit a message](/docs/chats/messages/update)
