
## Update message

`PATCH /v1/bots/:botId/messages/:messageId`

Updates a message previously sent by the bot. The bot can only update its own messages.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `botId` (path) | number | yes | Bot ID. List: [`GET /v1/bots`](/docs/bots/management/list) |
| `messageId` (path) | number | yes | Bot message ID. It arrives in the `data.id` field of the [`POST /v1/bots/:botId/messages`](/docs/bots/messages/send) response and in the `message.id` field of [bot events](/docs/bots/events/bot-events) |

## Request fields (body)

All fields are optional, but the body must contain at least one of them.

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `message` | string | no | New message text (up to 20,000 characters). Supports [BB-codes](/docs/bots/messages/formatting) |
| `keyboard` | array | no | New [keyboard](/docs/bots/messages/keyboard). To remove it, pass `"N"` |
| `attach` | array/object | no | New [ATTACH blocks](/docs/bots/messages/attach) |
| `urlPreview` | boolean | no | Show link previews |

## Examples

### curl — personal key

```bash
curl -X PATCH https://vibecode.bitrix24.com/v1/bots/42/messages/1502 \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Updated message text",
    "keyboard": [
      {
        "TEXT": "Done",
        "BG_COLOR_TOKEN": "primary",
        "DISABLED": "Y"
      }
    ]
  }'
```

### curl — OAuth application

```bash
curl -X PATCH https://vibecode.bitrix24.com/v1/bots/42/messages/1502 \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Updated message text",
    "keyboard": [
      {
        "TEXT": "Done",
        "BG_COLOR_TOKEN": "primary",
        "DISABLED": "Y"
      }
    ]
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/messages/1502', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    message: 'Updated message text',
    keyboard: [
      {
        TEXT: 'Done',
        BG_COLOR_TOKEN: 'primary',
        DISABLED: 'Y',
      },
    ],
  }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/messages/1502', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    message: 'Updated message text',
    keyboard: [
      {
        TEXT: 'Done',
        BG_COLOR_TOKEN: 'primary',
        DISABLED: 'Y',
      },
    ],
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `data.result` | boolean | `true` on successful update |

## Response example

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

## Error response example

403 — the message does not belong to the bot or does not exist:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ACCESS_DENIED",
    "message": "Access denied"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_BOT_ID` | `botId` is not a number |
| 400 | `INVALID_PARAMS` | `messageId` in the path must be a positive integer from `1` to `9007199254740991`, without a sign, leading zeros, fraction, exponent or whitespace. Rejected before calling Bitrix24 |
| 400 | `MESSAGE_REQUIRED` | The body carries neither `message` nor any other content key. An empty `message` string does not count as content |
| 404 | `BOT_NOT_FOUND` | No bot found with this ID |
| 403 | `BOT_ACCESS_DENIED` | The bot belongs to a different API key |
| 403 | `BITRIX_ACCESS_DENIED` | The message does not belong to the bot or does not exist. A bot updates only its own messages |
| 422 | `BITRIX_ERROR` | Another Bitrix24 error, text in `message` |
| 403 | `SCOPE_DENIED` | The API key does not have the `imbot` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — see [access rights](/docs/access-rights) |
| 410 | `BOT_DISABLED` | The bot is disabled and does not process API calls. How to restore it — [Bot disabled](/docs/bots/troubleshooting#bot-disabled-bot_disabled) |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |

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

## Known specifics

**System messages cannot be updated:** messages sent with `system: true` have `authorId = 0` and do not belong to the bot from a permissions standpoint, so a request to update them fails with an error.

## See also

- [Send message](/docs/bots/messages/send)
- [Delete message](/docs/bots/messages/delete)
- [Keyboard](/docs/bots/messages/keyboard)
- [Bot platform](/docs/bots)
- [Limits and optimization](/docs/optimization)
