For AI agents: markdown of this page — /docs-content-en/chats/messages/comments-context.md documentation index — /llms.txt
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 |
|---|---|---|---|---|
Parameterchat (path) |
Typenumber | Requiredyes | Default— | DescriptionThe positive integer ID of the comment chat. In comment information, use the numeric part of data.commentInfo[].dialogId |
Parameterrange (query) |
Typeinteger | Requiredno | Default50 | DescriptionThe 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
curl "https://vibecode.bitrix24.com/v1/chats/comments/725/context?range=0" \
-H "X-Api-Key: YOUR_API_KEY"
curl — OAuth application
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
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
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. 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
{
"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
{
"success": false,
"error": {
"code": "BITRIX_ERROR",
"message": "MESSAGE_NOT_FOUND",
"b24Code": "MESSAGE_NOT_FOUND"
}
}
Errors
| HTTP | Code | Description |
|---|---|---|
| HTTP400 | CodeINVALID_PARAMS |
DescriptionInvalid chat ID, unknown, duplicate or malformed query parameter, or a request body |
| HTTP401 | CodeTOKEN_MISSING |
DescriptionThe key needs a Bitrix24 connection |
| HTTP403 | CodeSCOPE_DENIED |
DescriptionThe key requires the im scope |
| HTTP403 | CodeWRITE_BLOCKED_READONLY_KEY |
DescriptionOnly an ordinary employee personal key can make this request in READONLY mode |
| HTTP403 | CodeBITRIX_ACCESS_DENIED |
DescriptionBitrix24 denied access to the post or channel |
| HTTP404 | CodeENTITY_NOT_FOUND |
DescriptionBitrix24 returned a generic NOT_FOUND or ERROR_NOT_FOUND code, or a not-found message |
| HTTP422 | CodeBITRIX_ERROR |
DescriptionBitrix24 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 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.