For AI agents: markdown of this page — /docs-content-en/partner-connect/token.md documentation index — /llms.txt

Exchange a code for an API key

POST /v1/connect/token

Exchanges a one-time authorization code for a permanent API key. Accepts application/json and application/x-www-form-urlencoded.

Request fields (body)

Field Type Required Description
Fieldgrant_type Typestring Requiredyes Descriptionauthorization_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).
Fieldclient_id Typestring Requiredyes DescriptionPartner identifier
Fieldclient_secret Typestring Requiredconditional DescriptionPartner secret. Required for a confidential client. Pass it only from the server side. A public client (PUBLIC) does not pass it
Fieldcode Typestring Requiredyes DescriptionCode from the code parameter of the redirect
Fieldredirect_uri Typestring Requiredyes DescriptionThe same redirect_uri that was passed to /v1/connect/authorize
Fieldcode_verifier Typestring Requiredconditional DescriptionOriginal PKCE string. Required if code_challenge was passed during authorization, including for a client with a secret

Examples

The 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.

curl — OAuth application

Terminal
curl -X POST https://vibecode.bitrix24.com/v1/connect/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d grant_type=authorization_code \
  -d client_id=YOUR_CLIENT_ID \
  -d client_secret=YOUR_CLIENT_SECRET \
  -d code=RECEIVED_CODE \
  -d redirect_uri=https://yourapp.com/callback

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/connect/token', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    grant_type: 'authorization_code',
    client_id: 'YOUR_CLIENT_ID',
    client_secret: 'YOUR_CLIENT_SECRET',
    code: receivedCode,
    redirect_uri: 'https://yourapp.com/callback',
  }),
})

const data = await res.json()
// data.api_key — permanent Vibecode API key
// data.portal — Bitrix24 account selected by the user
// data.scopes — requested scopes, data.granted_scopes — scopes of the key
// data.user — user who granted access

Response fields

Field Type Description
Fieldapi_key Typestring DescriptionVibecode API key in the vibe_api_... format. Pass it in the X-Api-Key header in subsequent calls
Fieldportal.domain Typestring DescriptionBitrix24 account domain, for example example.bitrix24.com
Fieldportal.name Typestring DescriptionBitrix24 account name
Fieldscopes Typestring[] DescriptionScopes requested by the application. On the consent page the user confirms the set as a whole
Fieldgranted_scopes Typestring[] DescriptionScopes 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
Fielduser.name Typestring DescriptionName of the user who granted access
Fielduser.email Typestring DescriptionUser's email address

The two scope sets differ only for applications whose scopes are assigned by the platform itself — for example, the Cowork 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.

The 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.

The 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.

Response example

JSON
{
  "api_key": "vibe_api_...",
  "portal": {
    "domain": "example.bitrix24.com",
    "name": "My company"
  },
  "scopes": ["crm", "task"],
  "granted_scopes": ["crm", "task"],
  "user": {
    "name": "John Smith",
    "email": "john@example.com"
  }
}

Error response example

400 — a required parameter is missing:

JSON
{
  "error": "invalid_request",
  "error_description": "Missing client_id, code or redirect_uri"
}

Errors

The 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.

HTTP error Condition
HTTP400 errorinvalid_request ConditionOne of client_id, code, redirect_uri is missing
HTTP400 errorinvalid_grant ConditionThe code does not exist, has expired or was already used, or redirect_uri does not match the one passed to /v1/connect/authorize
HTTP400 errorinvalid_grant ConditionPKCE 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
HTTP400 errorinvalid_client ConditionA public client sent client_secret — a public client is not issued a secret and must not pass one
HTTP400 errorunsupported_grant_type Conditiongrant_type is missing or is not one of the modes listed in the grant_type field above
HTTP401 errorinvalid_client Conditionclient_id is unknown, the client is disabled, or client_secret does not match
HTTP403 erroraccess_denied ConditionThe 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
HTTP400 errorinvalid_request ConditionDevice sign-in polling: client_id or device_code is missing. error_description is Missing client_id or device_code
HTTP401 errorinvalid_client ConditionDevice sign-in polling: the client is unknown, disabled, or not allowed to use device sign-in
HTTP400 errorunauthorized_client ConditionDevice sign-in polling from a client in COMPANY mode. code and error_description are both CONNECT_COMPANY_DEVICE_FLOW_FORBIDDEN
HTTP429 errorslow_down ConditionThe 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

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.

Denials 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.

For the full reference of common API errors, see Errors.

See also