Find Message in Chat im.dialog.messages.search
Choose a tool for developing with an AI agent:
- use Alaio Vibecode to build an app for Bitrix24 from a task description without knowing any programming language. The agent writes the code and deploys the app to a server, with no manual hosting setup
- use the MCP server to develop a REST API integration in your own project. The agent refers to the official REST documentation
Scope:
imWho can execute the method: chat participant
The method im.dialog.messages.search performs a search for messages in the chat.
Method Parameters
Required parameters are marked with *
|
Name |
Description |
|
CHAT_ID* |
Identifier of the chat in which the search is performed |
|
SEARCH_MESSAGE |
Search string for the message text. Search for this parameter is performed for strings longer than 2 characters |
|
DATE_FROM |
Start of the search period in ISO 8601 format (RFC3339) |
|
DATE_TO |
End of the search period in ISO 8601 format (RFC3339) |
|
DATE |
Search for messages on a specific date in ISO 8601 format (RFC3339). If the parameter is provided, the search is performed within 24 hours from the specified date |
|
ORDER |
Sorting parameters. Supported field:
Default: |
|
LIMIT |
Number of messages returned. Default value: |
|
LAST_ID |
Identifier of the last message from the previous selection for pagination |
Code Examples
How to Use Examples in Documentation
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"CHAT_ID":3,"SEARCH_MESSAGE":"test","ORDER":{"ID":"DESC"},"LIMIT":20}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/im.dialog.messages.search
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"CHAT_ID":3,"SEARCH_MESSAGE":"test","ORDER":{"ID":"DESC"},"LIMIT":20,"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/im.dialog.messages.search
// This snippet is an ES module: top-level await requires type="module" or a bundler.
// $b24 is an already-initialized SDK instance (see the SDK "Get started" guide).
import { Text } from '@bitrix24/b24jssdk'
import type { B24Frame, ISODate } from '@bitrix24/b24jssdk'
declare const $b24: B24Frame
// Shape of the payload returned in result (match the "response handling" section of the page)
type DialogMessagesSearchResult = {
messages: Array<{
id: number
chat_id: number
author_id: number
date: ISODate
text: string
isSystem: boolean
uuid: string | null
forward: object | null
params: unknown[]
viewedByOthers: boolean
unread: boolean
viewed: boolean
}>
users: unknown[]
files: unknown[]
additionalMessages: unknown[]
copilot: object | null
stickers: unknown[]
reactions: unknown[]
tariffRestrictions: { isHistoryLimitExceeded: boolean }
usersShort: unknown[]
}
try {
const response = await $b24.actions.v2.call.make<DialogMessagesSearchResult>({
method: 'im.dialog.messages.search',
params: {
CHAT_ID: 3,
SEARCH_MESSAGE: 'test',
ORDER: { ID: 'DESC' },
LIMIT: 20,
},
requestId: Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
} else {
const result = response.getData()!.result
console.info('Found messages:', result.messages.length, result.messages)
}
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
<!-- Load the SDK (UMD build); it is exposed as the global B24Js -->
<script src="https://unpkg.com/@bitrix24/b24jssdk@1/dist/umd/index.min.js"></script>
<script>
async function searchDialogMessages() {
try {
// Initialize the SDK inside a Bitrix24 frame
const $b24 = await B24Js.initializeB24Frame()
const response = await $b24.actions.v2.call.make({
method: 'im.dialog.messages.search',
params: {
CHAT_ID: 3,
SEARCH_MESSAGE: 'test',
ORDER: { ID: 'DESC' },
LIMIT: 20,
},
requestId: B24Js.Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
return
}
const result = response.getData().result
console.info('Found messages:', result.messages.length, result.messages)
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
}
document.addEventListener('DOMContentLoaded', searchDialogMessages)
</script>
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
try:
bitrix_response = client.im.dialog.messages.search(
chat_id=3,
search_message="test",
order={
"ID": "DESC",
},
limit=20,
).response
result = bitrix_response.result
print(result)
except BitrixAPIError as error:
print(
"Bitrix API error",
f"error: {error.error}",
f"error_description: {error.error_description}",
sep="\n",
)
except BitrixSDKException as error:
print(f"Bitrix SDK error: {error.message}")
except Exception as error:
print(f"Unexpected error: {error}")
try {
$response = $b24Service
->core
->call(
'im.dialog.messages.search',
[
'CHAT_ID' => 3,
'SEARCH_MESSAGE' => 'test',
'ORDER' => ['ID' => 'DESC'],
'LIMIT' => 20,
]
);
$result = $response
->getResponseData()
->getResult();
echo 'Success: ' . print_r($result, true);
} catch (Throwable $e) {
error_log($e->getMessage());
echo 'Error: ' . $e->getMessage();
}
BX24.callMethod(
'im.dialog.messages.search',
{
CHAT_ID: 3,
SEARCH_MESSAGE: 'test',
ORDER: { ID: 'DESC' },
LIMIT: 20
},
function(result)
{
if (result.error())
{
console.error(result.error());
}
else
{
console.log(result.data());
}
}
);
require_once('crest.php');
$result = CRest::call(
'im.dialog.messages.search',
[
'CHAT_ID' => 3,
'SEARCH_MESSAGE' => 'test',
'ORDER' => ['ID' => 'DESC'],
'LIMIT' => 20,
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
// client and ctx are already created — see the Go SDK section
res, err := client.Core().Call(ctx, "im.dialog.messages.search", b24.Params{
"CHAT_ID": 3,
"SEARCH_MESSAGE": "test",
"ORDER": b24.Params{
"ID": "DESC",
},
"LIMIT": 20,
})
if err != nil {
return fmt.Errorf("im.dialog.messages.search: %w", err)
}
// The response shape is shown below on this page.
fmt.Printf("%s\n", res.Result)
Response Handling
HTTP status: 200
{
"result": {
"users": [
{
"id": 1,
"active": true,
"name": "Alex",
"firstName": "Alex",
"lastName": "",
"workPosition": "",
"color": "#df532d",
"avatar": "https://cdn-com.bitrix24.com/path/avatar.jpg",
"avatarHr": "https://cdn-com.bitrix24.com/path/avatar.jpg",
"gender": "F",
"birthday": "",
"extranet": false,
"network": false,
"bot": false,
"connector": false,
"externalAuthId": "socservices",
"status": "online",
"idle": false,
"lastActivityDate": "2026-02-13T14:27:33+01:00",
"mobileLastDate": false,
"desktopLastDate": false,
"absent": false,
"departments": [1, 107, 47, 3],
"phones": {
"personal_mobile": "19998887766",
"inner_phone": "111"
},
"botData": null,
"type": "user",
"website": "",
"email": "user@example.com"
}
],
"files": [],
"additionalMessages": [],
"copilot": null,
"stickers": [],
"reactions": [],
"tariffRestrictions": {
"isHistoryLimitExceeded": false
},
"usersShort": [],
"messages": [
{
"id": 33653,
"chatId": 2421,
"chat_id": 2421,
"authorId": 1,
"author_id": 1,
"date": "2026-02-13T14:28:00+01:00",
"text": "test message",
"isSystem": false,
"uuid": "18533186-232b-4423-8438-64501da182f5",
"forward": null,
"params": [],
"viewedByOthers": false,
"block": null,
"unread": false,
"viewed": true,
"viewedCount": 0
}
]
},
"time": {
"start": 1770982150,
"finish": 1770982150.503861,
"duration": 0.5038609504699707,
"processing": 0,
"date_start": "2026-02-13T14:29:10+01:00",
"date_finish": "2026-02-13T14:29:10+01:00",
"operating_reset_at": 1770982750,
"operating": 0
}
}
Returned Data
|
Name |
Description |
|
result |
Root element of the response |
|
result.messages |
Array of found messages (detailed description) |
|
result.users |
Users associated with the found messages (detailed description) |
|
result.files |
Files from the found messages |
|
result.additionalMessages |
Additional messages related to the found ones, such as forwarded or quoted (detailed description) |
|
result.copilot |
BitrixGPT data, if present in the response. Can be |
|
result.stickers |
Stickers associated with the found messages |
|
result.reactions |
Reactions to the found messages (detailed description) |
|
result.tariffRestrictions |
Information about tariff restrictions on history. Contains the flag |
|
result.usersShort |
Brief information about users who reacted. Used as a supplementary reference to |
|
time |
Information about the request execution time |
Message
|
Name |
Description |
|
id |
Identifier of the message |
|
chatId |
Identifier of the chat |
|
chat_id |
Identifier of the chat. A duplicate of the |
|
authorId |
Identifier of the message author |
|
author_id |
Identifier of the message author. A duplicate of the |
|
date |
Date and time of message creation |
|
text |
Text of the message |
|
isSystem |
Indicator of a system message |
|
uuid |
External UUID of the message. Can be |
|
forward |
Information about forwarding. Can be |
|
params |
Message parameters |
|
viewedByOthers |
Indicator that the message has been viewed by other participants |
|
unread |
Indicator of an unread message for the current user |
|
viewed |
Indicator that the message has been viewed by the current user |
|
viewedCount |
Number of participants who have viewed the message |
|
block |
Service data of the message block. Can be |
User
|
Name |
Description |
|
id |
Identifier of the user |
|
active |
User is active |
|
name |
Full name |
|
firstName |
First name |
|
lastName |
Last name |
|
workPosition |
Position |
|
color |
Profile color in hex format |
|
avatar |
Avatar URL |
|
avatarHr |
High-resolution avatar URL |
|
gender |
Gender |
|
birthday |
Birthday |
|
extranet |
Indicator of an extranet user |
|
network |
Indicator of a Bitrix24 Network user |
|
bot |
Indicator of a bot |
|
connector |
Indicator of a connector user |
|
externalAuthId |
External authorization code |
|
status |
User status |
|
idle |
Indicator of inactivity |
|
lastActivityDate |
Date and time of last activity |
|
mobileLastDate |
Last activity in the mobile app. Can be |
|
desktopLastDate |
Last activity in the desktop app. Can be |
|
absent |
Indicator of absence |
|
departments |
Array of department identifiers |
|
phones |
User's phones |
|
botData |
Additional bot data. For a regular user |
|
type |
User type |
|
website |
User's website |
|
email |
User's e-mail |
Reactions
|
Name |
Description |
|
messageId |
Identifier of the message |
|
reactionCounters |
Count of reactions by each type |
|
reactionUsers |
Users by types of reactions |
|
ownReactions |
Reactions of the current user |
Error Handling
HTTP status: 400, 403
{
"error": "CHAT_ID_EMPTY",
"error_description": "CHAT_ID can't be empty"
}
|
Name |
Description |
|
error |
String error code. It consists of digits, Latin letters, and underscores. It may arrive empty — in that case only |
|
error_description |
Error message for the developer. Do not show it to the end user without processing |
Possible Error Codes
|
Code |
Description |
Value |
|
|
CHAT_ID can't be empty |
Required parameter |
|
|
You do not have access to this chat |
No access to the specified chat |
Statuses and System Error Codes
HTTP Status: 4xx, 5xx
The errors described below are returned by the REST API itself, not by the logic of a specific method. They can arrive in response to any method.
|
Status |
Code |
Description |
|
|
|
An internal server error has occurred. Retry the call, and if the error persists, contact the server administrator or Bitrix24 technical support |
|
|
|
The server returned an unexpected response. Retry the call, and if the error persists, contact the server administrator or Bitrix24 technical support |
|
|
|
The request intensity limit has been exceeded |
|
|
|
The method is blocked because the request resource intensity limit has been exceeded. The block is lifted automatically once the accumulated execution time of the method no longer exceeds the limit |
|
|
|
The request contains no authorization data: neither an access token nor a webhook code was passed |
|
|
|
Methods are called over the HTTPS protocol only |
|
|
|
The REST API is blocked due to overload. This is a manual individual block. To have it lifted, contact Bitrix24 technical support |
|
|
|
REST API access is not active for this account. In Bitrix24 Cloud, check the current plan or trial status: Vibe+ plans include REST API access, while Essentials plans do not. A webhook receives a different error message — |
|
|
|
No active webhook with the specified user identifier and secret code was found |
|
|
|
No method with this name was found. The name is misspelled, the method does not exist in the REST API, or it is unavailable without the required scope |
|
|
|
The request requires broader permissions than the token has: for a webhook these are the permissions granted to it, for an application it is the scope. For an application, the error message ends with |
|
|
|
The access token has expired |
|
|
|
The application is installed, but the Bitrix24 administrator has granted access to it only to specific users |
|
|
|
The public part of the site is closed. To open it on an on-premise installation, disable the "Temporary closure of the public part of the site" option. Path to the setting: Desktop > Settings > Product Settings > Module Settings > Main Module > Temporary closure of the public part of the site |
Continue Learning
- Retrieve a List of Recent Messages im.dialog.messages.get
- Set the "read" flag for messages im.dialog.read
- Set the "unread" flag for messages im.dialog.unread
- Send "User is typing" indicator im.dialog.writing
- Send Message im.message.add
- Update Message im.message.update
- Delete Message im.message.delete