
## Edit a message

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

Updates the text of a previously sent message. The original text cannot be restored after editing via the API — create a new message 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) |

## Request body fields

| Field | Type | Req. | Description |
|------|-----|:-----:|---------|
| `message` | string | yes | New message text (up to 20,000 characters) |

## Message layout

- [Text formatting](/docs/chats/messages/formatting) — BB codes in the message text

## Examples

### curl — personal key

```bash
curl -X PATCH https://vibecode.bitrix24.com/v1/chats/42/messages/36889 \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Invoice confirmed. Thank you."
  }'
```

### curl — OAuth application

```bash
curl -X PATCH https://vibecode.bitrix24.com/v1/chats/42/messages/36889 \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Invoice confirmed. Thank you."
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/42/messages/36889', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    message: 'Invoice confirmed. Thank you.',
  }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/42/messages/36889', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    message: 'Invoice confirmed. Thank you.',
  }),
})

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

## Response fields

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

## 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 — message not found, unavailable, or empty text (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 cannot be edited.** Messages sent with `system: true` have `authorId = 0`. They cannot be changed — the response returns an error.

**Only the text changes.** The endpoint updates the message text. It cannot replace the keyboard or attachments of a sent message.

## See also

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