## Unread mark

`POST /v1/chats/:dialogId/unread`

`DELETE /v1/chats/:dialogId/unread`

Sets and clears the "unread" mark on the chat's row in the recent dialog list — the mark the messenger shows after the "Mark as unread" command. The mark is independent of the unread message counter: it neither marks messages as read nor makes them unread.

- `POST` sets the mark — the v2 messenger method `im.v2.Chat.unread`.
- `DELETE` clears the mark — the method `im.v2.Chat.read` with `onlyRecent: Y`. The "[read later](/docs/chats/messages/mark)" pointer is cleared together with the mark. Messages are not marked as read — use [`POST /v1/chats/:dialogId/read`](/docs/chats/messages/read) for that.

Both calls are writes: a read-only key gets `403 WRITE_BLOCKED_READONLY_KEY` before any call to Bitrix24.

## Parameters

| Parameter | Type | Required | Default | Description |
|----------|-----|:-----:|-----------|---------|
| `dialogId` (path) | string | yes | — | Dialog ID: `chatXXX` for a group chat, a user ID for a direct dialog, or the `me` alias |

There are no query parameters and no body fields. Any query parameter or body field is rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
# Set the mark
curl -X POST "https://vibecode.bitrix24.com/v1/chats/chat123/unread" \
  -H "X-Api-Key: YOUR_API_KEY"

# Clear the mark
curl -X DELETE "https://vibecode.bitrix24.com/v1/chats/chat123/unread" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

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

const { data } = await res.json()
console.log('Unread messages:', data.counter)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/chat123/unread', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

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

## Response fields

`POST`:

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data.result` | boolean | Always `true` — Bitrix24 returns it regardless of the outcome, see "Known specifics" |

`DELETE`:

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data.chatId` | number | Chat ID |
| `data.lastId` | number | ID of the last read message |
| `data.counter` | number | Number of unread messages after the call — the mark does not affect it |
| `data.viewedMessages` | array | IDs of messages marked as read. Empty when the mark is cleared |

## Response example

`POST`:

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

`DELETE`:

```json
{
  "success": true,
  "data": {
    "chatId": 123,
    "lastId": 1002,
    "counter": 0,
    "viewedMessages": []
  }
}
```

## Error response example

400 — a body field was sent:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Body field `unread` is not accepted by POST /v1/chats/:dialogId/unread. It takes no body fields."
  }
}
```

422 — the chat is not in the recent dialog list (`DELETE`):

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

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | A query parameter or a body field was sent, or the body is not a JSON object. Checked before any call to Bitrix24 |
| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — the call changes the chat state |
| 403 | `BITRIX_ACCESS_DENIED` | `DELETE`: the chat does not exist or the user has no access to it |
| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |
| 404 | `ENTITY_NOT_FOUND` | Bitrix24 answered "not found"; the portal code is in `error.b24Code` |
| 422 | `BITRIX_ERROR` | Bitrix24 returned an error; the portal code is in `error.b24Code`. `POST` on a chat that does not exist — `CHAT_NOT_FOUND`; `DELETE` on a chat outside the recent dialog list — `READ_RECENT_ITEM_NOT_FOUND_ERROR` |
| 502 | `ME_ALIAS_RESOLUTION_FAILED` | Failed to resolve the user when using the `me` alias |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable or returned a server error |

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

## Known specifics

- **`POST` does not report whether the mark was set.** Bitrix24 returns `{ "result": true }` regardless of the outcome: when the chat is not in the current user's recent dialog list — for example, the chat was hidden from the list — the mark is not set, but the response is the same. To check the result, read the `unread` field of the chat's row in the [recent dialogs](/docs/chats/discovery/recent) in the v2 mode or `isMarkedAsUnread` in the [counters](/docs/chats/discovery/counters).
- **`DELETE` works only on a list row.** Bitrix24 refuses a chat outside the recent dialog list with the code `READ_RECENT_ITEM_NOT_FOUND_ERROR`. The row returns to the list when a new message arrives in the chat.
- The mark and the "read later" pointer are cleared by one call: they cannot be cleared separately.
- `POST` on a chat that is already marked changes nothing: the "read later" pointer, if set, stays where it was.

## See also

- [Read later](/docs/chats/messages/mark)
- [Mark as read](/docs/chats/messages/read)
- [Unread counters](/docs/chats/discovery/counters)
- [Chat management](/docs/chats/management)
