
## Read messages

`POST /v1/bots/:botId/chats/:dialogId/read`

Marks messages as read on behalf of the bot. Without `messageId`, marks all messages in the chat as read.

## Parameters

| Parameter | Type | Required | Default | Description |
|----------|-----|:-----:|-----------|---------|
| `botId` (path) | number | yes | — | Bot ID. Bot list: [`GET /v1/bots`](/docs/bots/management/list) |
| `dialogId` (path) | string | yes | — | Dialog ID: numeric user ID for direct messages (user list: [`GET /v1/users`](/docs/entities/users/list)), `chatXXX` for group chats — from the [Create a chat](/docs/bots/chats/create) response |

## Request fields (body)

| Parameter | Type | Required | Default | Description |
|----------|-----|:-----:|-----------|---------|
| `messageId` | number | no | — | Marks all messages up to and including this one as read. If omitted, all messages are marked as read. The ID comes in the [message event](/docs/bots/events) and in the [Send message](/docs/bots/messages/send) response |

## Examples

### curl — personal key

```bash
curl -X POST https://vibecode.bitrix24.com/v1/bots/42/chats/chat456/read \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "messageId": 1501 }'
```

### curl — OAuth application

```bash
curl -X POST https://vibecode.bitrix24.com/v1/bots/42/chats/chat456/read \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "messageId": 1501 }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/chats/chat456/read', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ messageId: 1501 }),
})

const { success, data } = await res.json()
console.log('Read up to:', data.lastId)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/bots/42/chats/chat456/read', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ messageId: 1501 }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | object | The chat's read state after the call |
| `data.chatId` | number | Numeric chat ID |
| `data.lastId` | number | ID of the message up to which the chat is marked as read |
| `data.counter` | number | Number of messages still unread by the bot in the chat |
| `data.viewedMessages` | number[] | IDs of the messages this call marked as read. The bot's own messages are not included. An empty array if there were no unread messages |

## Response example

```json
{
  "success": true,
  "data": {
    "chatId": 456,
    "lastId": 1501,
    "counter": 0,
    "viewedMessages": [1499, 1500, 1501]
  }
}
```

## Error response example

404 — bot not found:

```json
{
  "success": false,
  "error": {
    "code": "BOT_NOT_FOUND",
    "message": "Bot 999 not found. Register it first via POST /v1/bots."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_BOT_ID` | `botId` is not a number |
| 404 | `BOT_NOT_FOUND` | No bot found with this ID |
| 403 | `BOT_ACCESS_DENIED` | The bot belongs to a different API key |
| 422 | `BITRIX_ERROR` | Bitrix24 error (error text in `message`) |
| 403 | `SCOPE_DENIED` | The API key does not have the `imbot` scope |
| 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) |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |

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

## See also

- [Send message](/docs/bots/messages/send)
- [Get message](/docs/bots/messages/get)
- [Events](/docs/bots/events)
- [Bot platform](/docs/bots)
- [Limits and optimization](/docs/optimization)
