[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-partner-connect\u002Ftoken":3,"docs-tabs-partner-connect\u002Ftoken":6},{"content":4,"lastmod":5},"## Exchange a code for an API key\n\n`POST \u002Fv1\u002Fconnect\u002Ftoken`\n\nExchanges a one-time authorization code for a permanent API key. Accepts `application\u002Fjson` and `application\u002Fx-www-form-urlencoded`.\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|----------|\n| `grant_type` | string | yes | `authorization_code` for this flow. If it is missing, the endpoint responds with `unsupported_grant_type`. The other mode of the same endpoint is `urn:ietf:params:oauth:grant-type:device_code` (see [Device sign-in without a browser](\u002Fdocs\u002Fpartner-connect\u002Fdevice-authorize)). |\n| `client_id` | string | yes | Partner identifier |\n| `client_secret` | string | conditional | Partner secret. Required for a confidential client. Pass it only from the server side. A public client (`PUBLIC`) does not pass it |\n| `code` | string | yes | Code from the `code` parameter of the redirect |\n| `redirect_uri` | string | yes | The same `redirect_uri` that was passed to `\u002Fv1\u002Fconnect\u002Fauthorize` |\n| `code_verifier` | string | conditional | Original PKCE string. Required if `code_challenge` was passed during authorization, including for a client with a secret |\n\n## Examples\n\nThe endpoint authenticates with the application's credentials — `client_id` and `client_secret` in the request body. The `X-Api-Key` and `Authorization` headers are not needed.\n\n### curl — OAuth application\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fconnect\u002Ftoken \\\n  -H \"Content-Type: application\u002Fx-www-form-urlencoded\" \\\n  -d grant_type=authorization_code \\\n  -d client_id=YOUR_CLIENT_ID \\\n  -d client_secret=YOUR_CLIENT_SECRET \\\n  -d code=RECEIVED_CODE \\\n  -d redirect_uri=https:\u002F\u002Fyourapp.com\u002Fcallback\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fconnect\u002Ftoken', {\n  method: 'POST',\n  headers: { 'Content-Type': 'application\u002Fjson' },\n  body: JSON.stringify({\n    grant_type: 'authorization_code',\n    client_id: 'YOUR_CLIENT_ID',\n    client_secret: 'YOUR_CLIENT_SECRET',\n    code: receivedCode,\n    redirect_uri: 'https:\u002F\u002Fyourapp.com\u002Fcallback',\n  }),\n})\n\nconst data = await res.json()\n\u002F\u002F data.api_key — permanent Vibecode API key\n\u002F\u002F data.portal — Bitrix24 account selected by the user\n\u002F\u002F data.scopes — requested scopes, data.granted_scopes — scopes of the key\n\u002F\u002F data.user — user who granted access\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|----------|\n| `api_key` | string | Vibecode API key in the `vibe_api_...` format. Pass it in the `X-Api-Key` header in subsequent calls |\n| `portal.domain` | string | Bitrix24 account domain, for example `example.bitrix24.com` |\n| `portal.name` | string | Bitrix24 account name |\n| `scopes` | string[] | Scopes requested by the application. On the consent page the user confirms the set as a whole |\n| `granted_scopes` | string[] | Scopes the issued key actually carries. For a self-registered partner application it generally matches `scopes`. The two differ if the key's scopes were changed after consent |\n| `user.name` | string | Name of the user who granted access |\n| `user.email` | string | User's email address |\n\nThe two scope sets differ only for applications whose scopes are assigned by the platform itself — for example, the [Cowork](\u002Fdocs\u002Fcowork) desktop application. Such an application may request nothing, in which case `scopes` arrives empty and `granted_scopes` lists the key's full set. Check access against `granted_scopes`.\n\nThe `granted_scopes` field may be absent from the response if the platform could not read the scopes of the issued key. It never arrives empty, so an absent field means \"set unknown\", not \"no scopes\" — in such a response rely on `scopes`.\n\nThe `granted_scopes` set reflects what is recorded in the key. The Bitrix24 account may not confirm an individual scope on its side, so determine the cause of a denial from the Bitrix24 response code, not from whether the scope is in the list.\n\n## Response example\n\n```json\n{\n  \"api_key\": \"vibe_api_...\",\n  \"portal\": {\n    \"domain\": \"example.bitrix24.com\",\n    \"name\": \"My company\"\n  },\n  \"scopes\": [\"crm\", \"task\"],\n  \"granted_scopes\": [\"crm\", \"task\"],\n  \"user\": {\n    \"name\": \"John Smith\",\n    \"email\": \"john@example.com\"\n  }\n}\n```\n\n## Error response example\n\n400 — a required parameter is missing:\n\n```json\n{\n  \"error\": \"invalid_request\",\n  \"error_description\": \"Missing client_id, code or redirect_uri\"\n}\n```\n\n## Errors\n\nThe endpoint responds in RFC 6749 form — `{ error, error_description }`, without the `success` wrapper. This is for compatibility with off-the-shelf OAuth libraries. The exception is a denial by the endpoint's own rate limiter, whose form is described after the table.\n\n| HTTP | `error` | Condition |\n|------|---------|---------|\n| 400 | `invalid_request` | One of `client_id`, `code`, `redirect_uri` is missing |\n| 400 | `invalid_grant` | The code does not exist, has expired or was already used, or `redirect_uri` does not match the one passed to `\u002Fv1\u002Fconnect\u002Fauthorize` |\n| 400 | `invalid_grant` | PKCE verification failed: `code_verifier` was not passed or does not match the previously passed `code_challenge`. The code is consumed anyway: a retry with the correct `code_verifier` also returns `invalid_grant`, so start authorization over |\n| 400 | `invalid_client` | A public client sent `client_secret` — a public client is not issued a secret and must not pass one |\n| 400 | `unsupported_grant_type` | `grant_type` is missing or is not one of the modes listed in the `grant_type` field above |\n| 401 | `invalid_client` | `client_id` is unknown, the client is disabled, or `client_secret` does not match |\n| 403 | `access_denied` | The client is in `COMPANY` mode, and Company key issuance is refused. `code` and `error_description` carry the machine-readable reason: `CONNECT_COMPANY_NOT_READY` when the technical conditions for the connection are not met, `CONNECT_COMPANY_DISABLED` when the connection is unavailable for this user or Bitrix24 account. For details, see [Company connection](\u002Fdocs\u002Fpartner-connect\u002Fcompany) |\n| 400 | `invalid_request` | Device sign-in polling: `client_id` or `device_code` is missing. `error_description` is `Missing client_id or device_code` |\n| 401 | `invalid_client` | Device sign-in polling: the client is unknown, disabled, or not allowed to use device sign-in |\n| 400 | `unauthorized_client` | Device sign-in polling from a client in `COMPANY` mode. `code` and `error_description` are both `CONNECT_COMPANY_DEVICE_FLOW_FORBIDDEN` |\n| 429 | `slow_down` | The rate limit at the platform entry was exceeded. The limit is counted per caller address and is shared between code exchange and device polling. The response carries `Retry-After` with the minimum pause in seconds and no `X-RateLimit-*` headers |\n\n**There are two rate limiters, and both respond with `429`.** Tell them apart by the `X-RateLimit-Limit` header. A denial at the platform entry from the table above does not carry this header and comes in RFC 6749 form. A denial by the endpoint itself carries it, and the body comes in the common API envelope — `{ \"success\": false, \"error\": { \"code\": \"RATE_LIMITED\", \"message\": \"...\" } }`. The action is the same in both cases: wait, then retry with a longer pause each time.\n\nDenials of issuance, reconnection and secret rotation in `COMPANY` mode arrive with HTTP 400, 403, 409, 429 or 503 and a `code` field. The `429 CONNECT_COMPANY_ATTEMPT_LIMITED` denial also carries `retryAfterSeconds`. The full list is in [Reconnection and secret rotation](\u002Fdocs\u002Fpartner-connect\u002Fcompany#reconnection-and-secret-rotation).\n\nFor the full reference of common API errors, see [Errors](\u002Fdocs\u002Ferrors).\n\n## See also\n\n- [Start user authorization](\u002Fdocs\u002Fpartner-connect\u002Fauthorize)\n- [Public client: PKCE flow](\u002Fdocs\u002Fpartner-connect\u002Fpkce)\n- [Device sign-in without a browser](\u002Fdocs\u002Fpartner-connect\u002Fdevice-authorize)\n- [Key lifetime, revocation and limit](\u002Fdocs\u002Fpartner-connect\u002Fkeys)\n- [Partner Connect](\u002Fdocs\u002Fpartner-connect)\n","2026-11-19",{},1795415495253]