[{"data":1,"prerenderedAt":11},["ShallowReactive",2],{"docs-openlines\u002Fcrm":3,"docs-tabs-openlines\u002Fcrm":6},{"content":4,"lastmod":5},"# CRM chat actions\n\nActions on an Open Channels dialog linked to a lead, deal, company or contact: add an employee to the chat or remove one, write to the client, create a lead from an inquiry.\n\nBitrix24 API: `imopenlines.crm.*`\nScope: `imopenlines`\n\n## Operations\n\n- [Add an employee to a CRM chat](.\u002Fcrm\u002Fmembers-create.md) — `POST \u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers`\n- [Remove an employee from a CRM chat](.\u002Fcrm\u002Fmembers-delete.md) — `DELETE \u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers`\n- [Send a message to the client](.\u002Fcrm\u002Fmessages.md) — `POST \u002Fv1\u002Fopenlines\u002Fcrm\u002Fmessages`\n- [Create a lead from an inquiry](.\u002Fcrm\u002Flead.md) — `POST \u002Fv1\u002Fopenlines\u002Fdialogs\u002F:chatId\u002Flead`\n\n## Typical scenario\n\n1. Find the dialogs of a CRM card and their `chatId`: [`GET \u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats`](\u002Fdocs\u002Fopenlines\u002Fcrm-chats).\n2. Add an employee to the dialog: [`POST \u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers`](.\u002Fcrm\u002Fmembers-create.md).\n3. Write to the client in the selected dialog: [`POST \u002Fv1\u002Fopenlines\u002Fcrm\u002Fmessages`](.\u002Fcrm\u002Fmessages.md).\n\n## See also\n\n- [CRM chat members](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Fmembers)\n- [Chats by CRM card](\u002Fdocs\u002Fopenlines\u002Fcrm-chats)\n- [Open Channels](\u002Fdocs\u002Fopenlines)\n","2026-10-19",{"crm\u002Fmembers-create.md":7,"crm\u002Fmembers-delete.md":8,"crm\u002Fmessages.md":9,"crm\u002Flead.md":10},"## Add an employee to a CRM chat\n\n`POST \u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers`\n\nAdds an employee to an Open Channels chat linked to a lead, deal, contact or company, so a colleague can join the conversation about the CRM card.\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `crmEntityType` | string | yes | CRM object type: `lead`, `deal`, `company`, `contact`. Case-insensitive |\n| `crmEntityId` | number | yes | CRM object ID, a positive integer. List: [`GET \u002Fv1\u002Fleads`](\u002Fdocs\u002Fentities\u002Fleads\u002Flist), [`GET \u002Fv1\u002Fdeals`](\u002Fdocs\u002Fentities\u002Fdeals\u002Flist), [`GET \u002Fv1\u002Fcompanies`](\u002Fdocs\u002Fentities\u002Fcompanies\u002Flist), [`GET \u002Fv1\u002Fcontacts`](\u002Fdocs\u002Fentities\u002Fcontacts\u002Flist) |\n| `userId` | number | yes | ID of the employee to add to the chat. List: [`GET \u002Fv1\u002Fusers`](\u002Fdocs\u002Fentities\u002Fusers\u002Flist) |\n| `chatId` | number | no | ID of an Open Channels chat of this CRM object. List: [`GET \u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats`](\u002Fdocs\u002Fopenlines\u002Fcrm-chats) with `activeOnly=false`. If omitted, the object's last chat is used |\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"crmEntityType\": \"deal\", \"crmEntityId\": 42, \"userId\": 7, \"chatId\": 123}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"crmEntityType\": \"deal\", \"crmEntityId\": 42, \"userId\": 7, \"chatId\": 123}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    crmEntityType: 'deal',\n    crmEntityId: 42,\n    userId: 7,\n    chatId: 123,\n  }),\n})\n\nconst { success, data } = await res.json()\nconsole.log('Chat:', data.chatId)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    crmEntityType: 'deal',\n    crmEntityId: 42,\n    userId: 7,\n    chatId: 123,\n  }),\n})\n\nconst { success, data } = await res.json()\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | `true` when the employee is added |\n| `data.chatId` | number | ID of the chat the employee was added to. If `chatId` is omitted, this is the CRM object's last chat |\n| `data.userId` | number | ID of the added employee |\n| `data.added` | boolean | Always `true` |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"chatId\": 123,\n    \"userId\": 7,\n    \"added\": true\n  }\n}\n```\n\n## Error response example\n\n404 — the CRM object has no chat with the given `chatId`:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"ENTITY_NOT_FOUND\",\n    \"message\": \"CRM chat not found\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|----------|\n| 400 | `INVALID_PARAMS` | The body is not a JSON object, `crmEntityType` is missing or not in the list, `crmEntityId` or `userId` is missing or not a positive integer |\n| 400 | `INVALID_JSON_BODY` | The request body cannot be parsed as JSON |\n| 400 | `INVALID_CHAT_ID` | `chatId` is passed but is not a positive integer |\n| 404 | `ENTITY_NOT_FOUND` | Message `CRM chat not found`: the CRM object has no Open Channels chats, including finished ones, or `chatId` is not one of them. The check runs before the write, so chat membership does not change |\n| 404 | `ENTITY_NOT_FOUND` | Message `Record not found`: Bitrix24 did not find the chat when adding the employee |\n| 422 | `BITRIX_ERROR` | `error.b24Code` equals `CHAT_NOT_IN_CRM`: Bitrix24 did not confirm that the chat is linked to the CRM object |\n| 422 | `BITRIX_ERROR` | Bitrix24 rejected the request for another reason. The text is in `message` |\n| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 denied the key owner due to insufficient permissions |\n| 403 | `SCOPE_DENIED` | The key does not have the `imopenlines` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only |\n| 401 | `MISSING_API_KEY` | The `X-Api-Key` header was not passed |\n| 401 | `INVALID_API_KEY` | The key is not recognized |\n| 401 | `TOKEN_MISSING` | A personal key has no access to the Bitrix24 portal, or an application key was sent without a session token in `Authorization` |\n| 429 | `RATE_LIMITED` | The limit of 120 requests per minute per portal is exceeded. The limit is divided across platform replicas, so the code may arrive before the 120th request. The effective value for the key is in the `x-ratelimit-limit` header, the remaining quota in `x-ratelimit-remaining` |\n| 429 | `RATE_LIMITED` | Bitrix24 rejected the call under its request rate limit for the portal. The response carries a `Retry-After` header |\n| 502 | `OPENLINE_OPERATOR_FAILED` | Bitrix24 returned an unexpected write result: not a chat ID, or a chat other than the passed `chatId` |\n| 502 | `OPENLINE_OPERATOR_FAILED` | The card's chat list arrived in an unexpected shape. The check runs before the write, so chat membership does not change |\n| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable |\n| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond in time, so the result is unknown. Check the chat membership before retrying |\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## See also\n\n- [Remove an employee from a CRM chat](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Fmembers-delete)\n- [CRM chat members](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Fmembers)\n- [Chats by CRM card](\u002Fdocs\u002Fopenlines\u002Fcrm-chats)\n- [Send a message to the client](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Fmessages)\n","## Remove an employee from a CRM chat\n\n`DELETE \u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers`\n\nRemoves an employee from an Open Channels chat linked to a lead, deal, contact or company, when the colleague no longer takes part in the conversation about the CRM card.\n\n## Request fields (body)\n\nThe fields are passed in the JSON body, not in the query string.\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `crmEntityType` | string | yes | CRM object type: `lead`, `deal`, `company`, `contact`. Case-insensitive |\n| `crmEntityId` | number | yes | CRM object ID, a positive integer. List: [`GET \u002Fv1\u002Fleads`](\u002Fdocs\u002Fentities\u002Fleads\u002Flist), [`GET \u002Fv1\u002Fdeals`](\u002Fdocs\u002Fentities\u002Fdeals\u002Flist), [`GET \u002Fv1\u002Fcompanies`](\u002Fdocs\u002Fentities\u002Fcompanies\u002Flist), [`GET \u002Fv1\u002Fcontacts`](\u002Fdocs\u002Fentities\u002Fcontacts\u002Flist) |\n| `userId` | number | yes | ID of the employee to remove from the chat. List: [`GET \u002Fv1\u002Fusers`](\u002Fdocs\u002Fentities\u002Fusers\u002Flist) |\n| `chatId` | number | no | ID of an Open Channels chat of this CRM object. List: [`GET \u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats`](\u002Fdocs\u002Fopenlines\u002Fcrm-chats) with `activeOnly=false`. Without the field, the object's last chat is used |\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X DELETE \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"crmEntityType\": \"deal\", \"crmEntityId\": 42, \"userId\": 7, \"chatId\": 123}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X DELETE \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"crmEntityType\": \"deal\", \"crmEntityId\": 42, \"userId\": 7, \"chatId\": 123}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers', {\n  method: 'DELETE',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    crmEntityType: 'deal',\n    crmEntityId: 42,\n    userId: 7,\n    chatId: 123,\n  }),\n})\n\nconst { success, data } = await res.json()\nconsole.log('Chat:', data.chatId)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats\u002Fusers', {\n  method: 'DELETE',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    crmEntityType: 'deal',\n    crmEntityId: 42,\n    userId: 7,\n    chatId: 123,\n  }),\n})\n\nconst { success, data } = await res.json()\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | `true` when the employee is removed |\n| `data.chatId` | number | ID of the chat the employee was removed from. Without `chatId` in the request, the last chat of the CRM object |\n| `data.userId` | number | ID of the removed employee |\n| `data.deleted` | boolean | Always `true` |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"chatId\": 123,\n    \"userId\": 7,\n    \"deleted\": true\n  }\n}\n```\n\n## Error response example\n\n404 — the CRM object has no Open Channels chats:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"ENTITY_NOT_FOUND\",\n    \"message\": \"CRM chat not found\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|----------|\n| 400 | `INVALID_PARAMS` | The body is not a JSON object, `crmEntityType` is missing or not in the list, `crmEntityId` or `userId` is missing or not a positive integer |\n| 400 | `INVALID_JSON_BODY` | The request body cannot be parsed as JSON |\n| 400 | `INVALID_CHAT_ID` | `chatId` is passed but is not a positive integer |\n| 404 | `ENTITY_NOT_FOUND` | Message `CRM chat not found`: the CRM object has no Open Channels chats, including finished ones, or `chatId` is not one of them. The check runs before the write, so chat membership does not change |\n| 404 | `ENTITY_NOT_FOUND` | Message `Record not found`: Bitrix24 did not find the chat when removing the employee |\n| 422 | `BITRIX_ERROR` | `error.b24Code` equals `CHAT_NOT_IN_CRM`: Bitrix24 did not confirm that the chat is linked to the CRM object |\n| 422 | `BITRIX_ERROR` | Bitrix24 rejected the request for another reason. The text is in `message` |\n| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 denied access to the key owner due to insufficient permissions |\n| 403 | `SCOPE_DENIED` | The key does not have the `imopenlines` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only |\n| 401 | `MISSING_API_KEY` | The `X-Api-Key` header was not passed |\n| 401 | `INVALID_API_KEY` | The key is not recognized |\n| 401 | `TOKEN_MISSING` | A personal key has no access to the Bitrix24 portal, or an application key was sent without a session token in `Authorization` |\n| 429 | `RATE_LIMITED` | The limit of 120 requests per minute per portal is exceeded. The limit is divided across platform replicas, so the code may arrive before the 120th request. The effective value for the key is in the `x-ratelimit-limit` header, the remaining quota in `x-ratelimit-remaining` |\n| 429 | `RATE_LIMITED` | Bitrix24 rejected the call because the portal's request rate limit was exceeded. The response carries a `Retry-After` header |\n| 502 | `OPENLINE_OPERATOR_FAILED` | Bitrix24 returned an unexpected write result: not a chat ID, or a chat other than the passed `chatId` |\n| 502 | `OPENLINE_OPERATOR_FAILED` | The card's chat list arrived in an unexpected shape. The check runs before the write, so chat membership does not change |\n| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable |\n| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond in time, so the result is unknown. Check the chat membership before retrying |\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## See also\n\n- [Add an employee to a CRM chat](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Fmembers-create)\n- [CRM chat members](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Fmembers)\n- [Chats by CRM card](\u002Fdocs\u002Fopenlines\u002Fcrm-chats)\n","## Send a message to the client\n\n`POST \u002Fv1\u002Fopenlines\u002Fcrm\u002Fmessages`\n\nSends a message to the Open Channel chat linked to a CRM card. The message reaches the client in their messenger on behalf of the specified employee or bot.\n\n**Important:** a real client receives the message. Before calling, check that `chatId` belongs to the right dialog.\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|----------|\n| `crmEntityType` | string | yes | CRM card type: `lead`, `deal`, `company` or `contact`. Case-insensitive |\n| `crmEntityId` | number | yes | CRM card ID. Lists: [`GET \u002Fv1\u002Fleads`](\u002Fdocs\u002Fentities\u002Fleads\u002Flist), [`GET \u002Fv1\u002Fdeals`](\u002Fdocs\u002Fentities\u002Fdeals\u002Flist), [`GET \u002Fv1\u002Fcompanies`](\u002Fdocs\u002Fentities\u002Fcompanies\u002Flist), [`GET \u002Fv1\u002Fcontacts`](\u002Fdocs\u002Fentities\u002Fcontacts\u002Flist) |\n| `userId` | number | yes | ID of the employee or bot on whose behalf the message is sent. Employees: [`GET \u002Fv1\u002Fusers`](\u002Fdocs\u002Fentities\u002Fusers\u002Flist), bots: the `data.bots[].id` field in the [`GET \u002Fv1\u002Fbots`](\u002Fdocs\u002Fbots\u002Fmanagement\u002Flist) response |\n| `chatId` | number | yes | ID of this card's Open Channel chat — a positive integer without the `chat` prefix. List: [`GET \u002Fv1\u002Fopenlines\u002Fcrm\u002Fchats`](\u002Fdocs\u002Fopenlines\u002Fcrm-chats) with `activeOnly=false` |\n| `message` | string | yes | Message text. A whitespace-only string is not accepted |\n\nNumeric fields also accept a string of digits.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fmessages \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"crmEntityType\": \"deal\",\n    \"crmEntityId\": 42,\n    \"userId\": 7,\n    \"chatId\": 123,\n    \"message\": \"Hello! Your order is ready for pickup.\"\n  }'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fmessages \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"crmEntityType\": \"deal\",\n    \"crmEntityId\": 42,\n    \"userId\": 7,\n    \"chatId\": 123,\n    \"message\": \"Hello! Your order is ready for pickup.\"\n  }'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fmessages', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    crmEntityType: 'deal',\n    crmEntityId: 42,\n    userId: 7,\n    chatId: 123,\n    message: 'Hello! Your order is ready for pickup.',\n  }),\n})\n\nconst { success, data, error } = await res.json()\nif (!success) throw new Error(`${error.code}: ${error.message}`)\nconsole.log('Message ID:', data.messageId)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fcrm\u002Fmessages', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    crmEntityType: 'deal',\n    crmEntityId: 42,\n    userId: 7,\n    chatId: 123,\n    message: 'Hello! Your order is ready for pickup.',\n  }),\n})\n\nconst { success, data } = await res.json()\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|----------|\n| `success` | boolean | `true` when the message is sent |\n| `data.chatId` | number | Chat ID from the request |\n| `data.messageId` | number | ID of the sent message in the chat |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"chatId\": 123,\n    \"messageId\": 456\n  }\n}\n```\n\n## Error response example\n\n404 — the chat does not belong to the specified CRM card:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"ENTITY_NOT_FOUND\",\n    \"message\": \"CRM chat not found\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|----------|\n| 400 | `INVALID_PARAMS` | `crmEntityType` is missing or outside the list, `crmEntityId` or `userId` is missing or not a positive integer, or the request body is not a JSON object |\n| 400 | `INVALID_JSON_BODY` | The request body cannot be parsed as JSON |\n| 400 | `INVALID_CHAT_ID` | `chatId` is not a positive integer, including the `chat123` form |\n| 400 | `MISSING_REQUIRED_FIELDS` | `chatId` is missing, or `message` is missing, not a string, empty or whitespace-only |\n| 404 | `ENTITY_NOT_FOUND` | Message `CRM chat not found`: the CRM card has no chat with that `chatId`, closed ones included. The check runs before sending; the message is not sent |\n| 404 | `ENTITY_NOT_FOUND` | Message `Record not found`: Bitrix24 did not find the chat when sending |\n| 403 | `BITRIX_ACCESS_DENIED` | The employee making the call has no access to the CRM card or no permission to send the message |\n| 422 | `BITRIX_ERROR` | Bitrix24 refused to send; its code is returned in `error.b24Code` |\n| 502 | `OPENLINE_OPERATOR_FAILED` | Bitrix24 did not return a message ID. The message may still have been sent |\n| 502 | `OPENLINE_OPERATOR_FAILED` | The card's chat list came back in an unexpected shape. The check runs before sending; the message is not sent |\n| 403 | `SCOPE_DENIED` | The key lacks the `imopenlines` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only |\n| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |\n| 401 | `INVALID_API_KEY` | The key is not recognized |\n| 401 | `TOKEN_MISSING` | A personal key has no access to the Bitrix24 portal, or an application key was sent without a session token in `Authorization` |\n| 429 | `RATE_LIMITED` | The limit of 120 requests per minute per portal was exceeded. The limit is divided across platform replicas, so the code can arrive before the 120th request. The effective value for the key is in the `x-ratelimit-limit` header, the remaining quota is in `x-ratelimit-remaining` |\n| 429 | `RATE_LIMITED` | Bitrix24 rejected the call under its request rate limit for the portal. The response carries a `Retry-After` header |\n| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable or the connection to it dropped before the full response |\n| 503 | `BITRIX_TIMEOUT` | Bitrix24 accepted the call but did not respond in time. The message may still have been sent |\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n- **The chat is checked before sending.** Before sending, Vibecode matches `chatId` against all of the card's chats, closed dialogs included.\n- **Retry after a failure.** After `502 OPENLINE_OPERATOR_FAILED` or `503 BITRIX_TIMEOUT` the message may have reached the client. A repeated call sends it again, so check the dialog's messages before retrying.\n\n## See also\n\n- [Chats by CRM card](\u002Fdocs\u002Fopenlines\u002Fcrm-chats)\n- [CRM chat members](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Fmembers)\n- [Create a lead from an inquiry](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Flead)\n- [Session history](\u002Fdocs\u002Fopenlines\u002Fhistory)\n","## Create a lead from an inquiry\n\n`POST \u002Fv1\u002Fopenlines\u002Fdialogs\u002F:chatId\u002Flead`\n\nCreates a CRM lead from an open channel dialog and returns the CRM card the dialog is linked to after the call. If a CRM card is already linked to the dialog, no new lead is created and the existing link is returned.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|----------|\n| `chatId` (path) | number | yes | Open channel chat ID — a positive integer without the `chat` prefix. List: the `chatId` field in the [`POST \u002Fv1\u002Fopenlines\u002Fsessions\u002Fsearch`](\u002Fdocs\u002Fopenlines\u002Fsessions\u002Fsearch) response |\n\nThe request body is empty.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fdialogs\u002F123\u002Flead \\\n  -H \"X-Api-Key: YOUR_API_KEY\"\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fdialogs\u002F123\u002Flead \\\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 chatId = 123\nconst res = await fetch(`https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fdialogs\u002F${chatId}\u002Flead`, {\n  method: 'POST',\n  headers: { 'X-Api-Key': 'YOUR_API_KEY' },\n})\n\nconst { success, data, error } = await res.json()\nif (!success) throw new Error(`${error.code}: ${error.message}`)\nif (data.leadId === null) {\n  console.log(`Dialog already linked: ${data.crmEntityType} ${data.crmEntityId}`)\n} else {\n  console.log('Lead:', data.leadId)\n}\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst chatId = 123\nconst res = await fetch(`https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fopenlines\u002Fdialogs\u002F${chatId}\u002Flead`, {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n  },\n})\n\nconst { success, data } = await res.json()\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|----------|\n| `success` | boolean | `true` when the dialog's link was read after the call |\n| `data.chatId` | number | Chat ID from the request |\n| `data.crmEntityType` | string | Type of the CRM card the dialog is linked to: `lead`, `deal`, `company` or `contact` |\n| `data.crmEntityId` | number | ID of the CRM card the dialog is linked to |\n| `data.leadId` | number \\| null | Lead ID when the dialog is linked to a lead. `null` when the dialog is linked to a deal, company or contact |\n\n## Response example\n\nThe dialog is linked to a lead:\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"chatId\": 123,\n    \"crmEntityType\": \"lead\",\n    \"crmEntityId\": 42,\n    \"leadId\": 42\n  }\n}\n```\n\nA deal was already linked to the dialog:\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"chatId\": 123,\n    \"crmEntityType\": \"deal\",\n    \"crmEntityId\": 42,\n    \"leadId\": null\n  }\n}\n```\n\n## Error response example\n\n400 — `chatId` in the path is not a positive integer:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_CHAT_ID\",\n    \"message\": \"chatId must be a positive safe integer\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|----------|\n| 400 | `INVALID_JSON_BODY` | A request body was sent and cannot be parsed as JSON. Checked before the path `chatId` is parsed |\n| 400 | `INVALID_CHAT_ID` | `chatId` in the path is not a positive integer, including the `chat123` form, or is greater than 9007199254740991. Bitrix24 is not called |\n| 404 | `ENTITY_NOT_FOUND` | Bitrix24 did not find a chat with that `chatId` |\n| 403 | `BITRIX_ACCESS_DENIED` | The employee making the call has no rights to the dialog, so the lead is not created |\n| 403 | `BITRIX_ACCESS_DENIED` | Message `Bitrix24 refused the dialog: it is absent or inaccessible`: Bitrix24 accepted the call but denied reading the dialog's link. The lead may still have been created |\n| 422 | `BITRIX_ERROR` | Bitrix24 refused to create the lead; its code is returned in `error.b24Code` |\n| 502 | `OPENLINE_OPERATOR_FAILED` | Bitrix24 did not confirm the lead creation, or the dialog's CRM link could not be read after the call. The lead may still have been created |\n| 403 | `SCOPE_DENIED` | The key lacks the `imopenlines` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only |\n| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |\n| 401 | `INVALID_API_KEY` | The key is not recognized |\n| 401 | `TOKEN_MISSING` | A personal key has no access to the Bitrix24 portal, or an application key was sent without a session token in `Authorization` |\n| 429 | `RATE_LIMITED` | The limit of 120 requests per minute per portal was exceeded. The limit is divided across platform replicas, so the code can arrive before the 120th request. The effective value for the key is in the `x-ratelimit-limit` header, the remaining quota is in `x-ratelimit-remaining` |\n| 429 | `RATE_LIMITED` | Bitrix24 rejected the call under its request rate limit for the portal. The response carries a `Retry-After` header |\n| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable or the connection to it dropped before the full response |\n| 503 | `BITRIX_TIMEOUT` | Bitrix24 accepted the call but did not respond in time. The lead may still have been created |\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n- **Retrying after a failure is safe.** After `502 OPENLINE_OPERATOR_FAILED`, `503 BITRIX_TIMEOUT` and `403 BITRIX_ACCESS_DENIED` the call can be repeated: if the first call managed to create the lead, the repeated one does not create a second lead and returns the existing link.\n\n## See also\n\n- [Send a message to the client](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Fmessages)\n- [CRM chat members](\u002Fdocs\u002Fopenlines\u002Fcrm\u002Fmembers)\n- [Chats by CRM card](\u002Fdocs\u002Fopenlines\u002Fcrm-chats)\n- [Search sessions](\u002Fdocs\u002Fopenlines\u002Fsessions\u002Fsearch)\n- [Get a lead](\u002Fdocs\u002Fentities\u002Fleads\u002Fget)\n",1795000562980]