[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Fmessages\u002Fsearch":3,"docs-tabs-chats\u002Fmessages\u002Fsearch":6},{"content":4,"lastmod":5},"## Search messages in a chat\n\n`GET \u002Fv1\u002Fchats\u002F:dialogId\u002Fmessages\u002Fsearch`\n\nFinds the messages of one chat whose text contains the query string. The response has the shape of the [message history in the v2 mode](\u002Fdocs\u002Fchats\u002Fmessages\u002Flist): the messages found and the collections that go with them.\n\nTo search chats by title, use [chat search](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Fsearch).\n\n## Parameters\n\n| Parameter | Type | Required | Default | Description |\n|----------|-----|:-----:|-----------|---------|\n| `dialogId` (path) | string | yes | — | Dialog ID: numeric user ID for personal messages, `chatXXX` for group chats. The special `me` alias refers to the current user's personal dialog. `chatXXX` is the `id` field of a [recent dialogs](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Frecent) row; the user ID comes from the [user list](\u002Fdocs\u002Fentities\u002Fusers\u002Flist) |\n| `query` (query) | string | yes | — | Search string. At least 3 characters after trimming blanks |\n| `lastId` (query) | number | no | — | Cursor: the smallest message `id` of the previous page, the largest with `order=asc`. The boundary itself is not included |\n| `order` (query) | string | no | `desc` | `desc` — newest first, `asc` — oldest first |\n| `limit` (query) | number | no | 50 | Messages per page, from 1 to 200: a value outside the range is clamped; the passed and applied values are in `meta.requestedLimit` and `meta.appliedLimit` |\n\nAny other parameter or a repeated parameter is rejected with `400 INVALID_PARAMS`.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X GET \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fmessages\u002Fsearch?query=mockup&limit=20\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\"\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X GET \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fmessages\u002Fsearch?query=mockup&limit=20\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\"\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fmessages\u002Fsearch?query=mockup&limit=20', {\n  method: 'GET',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n  },\n})\n\nconst { data } = await res.json()\nconsole.log('Found:', data.messages.map((m) => m.id), 'has more:', data.hasNextPage)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fmessages\u002Fsearch?query=mockup&limit=20', {\n  method: 'GET',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n  },\n})\n\nconst { data } = await res.json()\nconsole.log('Found:', data.messages.map((m) => m.id), 'has more:', data.hasNextPage)\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.messages` | array | Messages found on the page |\n| `data.messages[].id` | number | Message ID |\n| `data.messages[].chatId` | number | Chat ID — equals `data.chat.id` in the [chat loading](\u002Fdocs\u002Fchats\u002Fmessages\u002Fload) response |\n| `data.messages[].authorId` | number | Author ID — the profile is in `data.users` of the same response or can be fetched [by user ID](\u002Fdocs\u002Fentities\u002Fusers\u002Fget). `0` — a system message |\n| `data.messages[].date` | string | Date sent (ISO 8601) |\n| `data.messages[].text` | string | Message text |\n| `data.users` | array | Authors of the messages found |\n| `data.usersShort` | array | Short user cards: `id`, `name`, `avatar`, `color`, `type` |\n| `data.files` | array | Files of the messages found |\n| `data.reactions` | array | Reactions to the messages found |\n| `data.additionalMessages` | array | Messages referenced by the messages found: quotes and replies |\n| `data.tariffRestrictions` | object | Plan restrictions on message history: `isHistoryLimitExceeded` |\n| `data.hasNextPage` | boolean | There are more matching messages after this page |\n| `meta.requestedLimit` | number | The `limit` passed, when it was outside the range from 1 to 200 |\n| `meta.appliedLimit` | number | The `limit` value applied — only when it was clamped to a bound |\n\nThe response also carries `stickers`, `forwardSource` and `copilot` — collections of the v2 message history shared by all responses that return messages.\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"messages\": [\n      {\n        \"id\": 1002,\n        \"chatId\": 42,\n        \"authorId\": 7,\n        \"date\": \"2026-09-20T10:01:00+00:00\",\n        \"text\": \"The mockup is ready for review\",\n        \"params\": {}\n      }\n    ],\n    \"users\": [\n      { \"id\": 7, \"name\": \"Anna Smith\", \"firstName\": \"Anna\", \"lastName\": \"Smith\", \"avatar\": \"\", \"type\": \"user\" }\n    ],\n    \"usersShort\": [\n      { \"id\": 7, \"name\": \"Anna Smith\", \"avatar\": \"\", \"color\": \"#df532d\", \"type\": \"user\" }\n    ],\n    \"files\": [],\n    \"reactions\": [],\n    \"stickers\": [],\n    \"additionalMessages\": [],\n    \"forwardSource\": null,\n    \"copilot\": null,\n    \"tariffRestrictions\": { \"isHistoryLimitExceeded\": false },\n    \"hasNextPage\": false\n  }\n}\n```\n\n## Error response example\n\n400 — the query is shorter than three characters:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_PARAMS\",\n    \"message\": \"`query` is required: at least 3 characters after trimming blanks.\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | No `query`, or it is shorter than 3 characters after trimming blanks. A parameter other than `query`, `lastId`, `order`, `limit`. A repeated parameter or an invalid value. Checked before any call to Bitrix24 |\n| 404 | `ENTITY_NOT_FOUND` | Bitrix24 reported \"not found\". The Bitrix24 code is in `error.b24Code` |\n| 422 | `BITRIX_ERROR` | Bitrix24 returned an error, for example `CHAT_NOT_FOUND`. The Bitrix24 code is in `error.b24Code` |\n| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |\n| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |\n| 502 | `ME_ALIAS_RESOLUTION_FAILED` | The `me` alias could not be resolved: Bitrix24 did not return the current user's ID |\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**Search may make you a member.** When the chat allows auto-join, search adds the current user as a member, as [loading a chat](\u002Fdocs\u002Fchats\u002Fmessages\u002Fload) does. A `READONLY` key may use this read operation. Search itself does not mark messages as read. The user's Bitrix24 permissions and the `im` scope are checked.\n\n**Matching is by substring.** The query `needle` also finds `probe-needle`. The `%` and `_` characters work as wildcards and are not escaped.\n\n**System messages are found too.** The system message about pinning quotes the pinned text, so it appears in the results along with the original. You can tell it apart by `authorId` `0`.\n\n**Continue in the message history.** To open the chat at a found message, use [messages around a message](\u002Fdocs\u002Fchats\u002Fmessages\u002Fcontext).\n\n## See also\n\n- [Read messages](\u002Fdocs\u002Fchats\u002Fmessages\u002Flist)\n- [Messages around a message](\u002Fdocs\u002Fchats\u002Fmessages\u002Fcontext)\n- [Chat search](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Fsearch)\n","2026-10-09",{},1794739550270]