## Messages around a channel post by comment chat

`GET /v1/chats/comments/:chat/context`

Returns the channel post linked to the comment chat and nearby messages from the channel. Use this endpoint to navigate to a channel post when you know the discussion ID. The key requires the `im` scope. Bitrix24 checks access to the post and its channel.

## Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|:--------:|---------|-------------|
| `chat` (path) | number | yes | — | The positive integer ID of the comment chat. In [comment information](/docs/chats/messages/comments), use the numeric part of `data.commentInfo[].dialogId` |
| `range` (query) | integer | no | 50 | The number of messages on each side of the post. Supply an integer of up to 15 digits. The endpoint clamps the value to 0 through 200. Use `range=0` for the post alone |

Send `range` at most once. The request accepts the path and this query parameter.

## Examples

### curl — personal key

```bash
curl "https://vibecode.bitrix24.com/v1/chats/comments/725/context?range=0" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl "https://vibecode.bitrix24.com/v1/chats/comments/725/context?range=0" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/chats/comments/725/context?range=0', {
  headers: { 'X-Api-Key': 'YOUR_API_KEY' },
})
const { data } = await response.json()
console.log(data?.messages[0]?.id)
```

### JavaScript — OAuth application

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/chats/comments/725/context?range=0', {
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})
const { data } = await response.json()
console.log(data?.messages[0]?.id)
```

## Response fields

The `data` fields match [messages around a message](/docs/chats/messages/context). The `data.messages[].chatId` field contains the channel ID. When the requested `range` is outside the allowed bounds, `meta.requestedRange` contains the original value and `meta.appliedRange` contains the applied value.

## Response example

```json
{
  "success": true,
  "data": {
    "messages": [
      {
        "id": 1002,
        "chatId": 42,
        "authorId": 7,
        "date": "2026-09-20T10:01:00+00:00",
        "text": "Meeting on Friday",
        "params": {}
      }
    ],
    "users": [],
    "files": [],
    "reactions": [],
    "hasPrevPage": true,
    "hasNextPage": false
  }
}
```

## Error response example

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

## Errors

| HTTP | Code | Description |
|------|------|-------------|
| 400 | `INVALID_PARAMS` | Invalid chat ID, unknown, duplicate or malformed query parameter, or a request body |
| 401 | `TOKEN_MISSING` | The key needs a Bitrix24 connection |
| 403 | `SCOPE_DENIED` | The key requires the `im` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | Only an ordinary employee personal key can make this request in `READONLY` mode |
| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 denied access to the post or channel |
| 404 | `ENTITY_NOT_FOUND` | Bitrix24 returned a generic `NOT_FOUND` or `ERROR_NOT_FOUND` code, or a not-found message |
| 422 | `BITRIX_ERROR` | Bitrix24 refused the request. The `error.b24Code` field carries the original code, for example `MESSAGE_NOT_FOUND` if the discussion has no linked post |

## Known specifics

The [message context](/docs/chats/messages/context) access rules apply. Bitrix24 updates the user's online presence and may add them to the channel when the channel allows auto-join. This request preserves the read state.

## See also

- [Comment information](/docs/chats/messages/comments)
- [Messages around a message](/docs/chats/messages/context)
