[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Fsharing\u002Fprimary-link":3,"docs-tabs-chats\u002Fsharing\u002Fprimary-link":6},{"content":4,"lastmod":5},"## Get the primary chat link\n\n`POST \u002Fv1\u002Fchats\u002F:dialogId\u002Fsharing-links\u002Fprimary`\n\nReturns the primary chat link and creates it if the link does not exist yet. A chat has one primary link, which cannot be revoked, and only a member with the right to manage the chat's links can obtain it.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|---------|\n| `dialogId` (path) | string | yes | Dialog ID: `chatXXX` for a group chat, a numeric user ID for a private chat, `me` — your personal dialog. List — [`GET \u002Fv1\u002Fchats\u002Frecent`](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Frecent) |\n\n## Request fields (body)\n\nThe body is optional.\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `generateIfNotExists` | boolean | no | `false` — only return the existing link without creating a new one. Defaults to `true` |\n\nOther body fields and query parameters are rejected with `400 INVALID_PARAMS`.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fsharing-links\u002Fprimary\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"generateIfNotExists\": false}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fsharing-links\u002Fprimary\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"generateIfNotExists\": false}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fsharing-links\u002Fprimary', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ generateIfNotExists: false }),\n})\n\nconst { success, data, error } = await res.json()\nconsole.log(success ? data.sharingLink.code : error.code)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat42\u002Fsharing-links\u002Fprimary', {\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({ generateIfNotExists: false }),\n})\n\nconst { success, data, error } = await res.json()\nconsole.log(success ? data.sharingLink.code : error.code)\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.sharingLink.id` | number | Link ID |\n| `data.sharingLink.entityType` | string | `chat` — a chat link |\n| `data.sharingLink.entityId` | string | Chat ID without the `chat` prefix |\n| `data.sharingLink.code` | string | The link code — for [joining by code](\u002Fdocs\u002Fchats\u002Fsharing\u002Fjoin) and for reading the link |\n| `data.sharingLink.type` | string | `primary` — the primary link |\n| `data.sharingLink.dateCreate` | string | Creation date, ISO 8601 |\n| `data.sharingLink.dateExpire` | string \\| null | Expiration date. `null` — no expiration |\n| `data.sharingLink.requireApproval` | boolean | Whether joining requires approval |\n| `data.sharingLink.url` | string | The link URL on the Bitrix24 account; the code is the value of its `IM_CODE` parameter |\n\n## Response example\n\nA link object of the same shape as for an [individual link](\u002Fdocs\u002Fchats\u002Fsharing\u002Findividual-link), with `type` equal to `primary`:\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"sharingLink\": {\n      \"id\": 1011,\n      \"entityId\": \"42\",\n      \"entityType\": \"chat\",\n      \"code\": \"Rt5wYn8KqL2vPz3M\",\n      \"type\": \"primary\",\n      \"dateCreate\": \"2026-09-24T23:01:10+00:00\",\n      \"dateExpire\": null,\n      \"requireApproval\": false,\n      \"url\": \"https:\u002F\u002Fportal.bitrix24.com\u002Fonline\u002F?IM_CODE=Rt5wYn8KqL2vPz3M\"\n    }\n  }\n}\n```\n\n## Error response example\n\n403 — a group chat, where the primary link is not issued to any member:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"BITRIX_ACCESS_DENIED\",\n    \"message\": \"ACCESS_DENIED\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | A body field other than `generateIfNotExists`, a body that is not an object, a `generateIfNotExists` that is neither `true` nor `false`, or a query parameter. Checked before any call to Bitrix24 |\n| 403 | `BITRIX_ACCESS_DENIED` | No right to manage the chat's links — Bitrix24 refused with the `ACCESS_DENIED` code |\n| 422 | `BITRIX_ERROR` | Bitrix24 returned an error; the portal code is in `error.b24Code`. `SHARING_LINK_NOT_FOUND` — no link exists and `generateIfNotExists: false` was passed. `CHAT_NOT_FOUND` — the chat does not exist on the portal |\n| 404 | `ENTITY_NOT_FOUND` | Bitrix24 answered with an unspecified \"not found\" code; the portal code is in `error.b24Code` |\n| 502 | `ME_ALIAS_RESOLUTION_FAILED` | Failed to resolve the user for the `me` alias |\n| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only and the call is a write — see [access rights](\u002Fdocs\u002Faccess-rights) |\n| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |\n\nThe full list of general API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**A group chat does not issue a primary link.** Bitrix24 grants no member, not even the owner, the right to manage a group chat's links, so the call returns `403 BITRIX_ACCESS_DENIED`. To invite an employee to such a chat by link, give them your [individual link](\u002Fdocs\u002Fchats\u002Fsharing\u002Findividual-link).\n\n**The primary link cannot be revoked.** [Revoking by code](\u002Fdocs\u002Fchats\u002Fsharing\u002Flink-revoke) removes only individual links.\n\n**The call is a write even without creating a link.** With `generateIfNotExists: false` no link is created, but a read-only key still gets `403 WRITE_BLOCKED_READONLY_KEY`: the call may make the key owner a chat member if the chat allows auto-join.\n\n## See also\n\n- [Get an individual chat link](\u002Fdocs\u002Fchats\u002Fsharing\u002Findividual-link)\n- [Get a link by code](\u002Fdocs\u002Fchats\u002Fsharing\u002Flink-get)\n- [Join a chat by code](\u002Fdocs\u002Fchats\u002Fsharing\u002Fjoin)\n- [Links and guests](\u002Fdocs\u002Fchats\u002Fsharing)\n","2026-10-01",{},1794739554726]