Untuk agen AI: markdown halaman ini — /docs-content-en/partner-connect.md indeks dokumentasi — /llms.txt

Artikel dokumentasi saat ini tersedia dalam bahasa Inggris.

Partner Connect

Connecting external services to Bitrix24: your application asks the user for permission to access their Bitrix24 account and receives a Vibecode API key for calls on that user's behalf. The flow follows the Authorization Code scheme — the same one used by the Google and GitHub OAuth providers.

Base URL: https://vibecode.bitrix24.com/v1 · Authorization: the application's client_id and client_secret · Key scopes: confirmed by the user on the consent page

When to use

Partner Connect is for an external service that works with its customers' Bitrix24 accounts: CRM analytics, ERP synchronization, a chat assistant, a landing page builder. A "Connect Bitrix24" button on your site starts the flow: the user picks a Bitrix24 account and confirms the scopes, and your server receives a permanent API key and works with the account on the user's behalf.

An application installed inside a Bitrix24 account that works only with that account does not need Partner Connect — a regular API key is enough, see Keys and authorization.

Documentation sections

How it works

Your application → [1. Redirect] → Vibecode consent page → [2. Consent]
    ↑                                                          ↓
    └──── [4. API key] ←── [3. Code to redirect_uri] ──────────┘
  1. Redirect. The application sends the user to GET /v1/connect/authorize with client_id, redirect_uri, state and a list of scopes.
  2. Consent. The user sees a Vibecode page, picks a Bitrix24 account and confirms or declines the requested scopes.
  3. Code. After approval the user returns to redirect_uri with the code and state parameters. If the user declines, they return with error=access_denied and state.
  4. Exchange. The application's server exchanges the code for an API key via POST /v1/connect/token.

Client types

The client type is chosen when the application is registered and cannot be changed later. It depends on one thing: whether the application has a place the user cannot reach where a secret can be stored.

Type When to choose Examples How the application proves its identity
TypeConfidential When to chooseThe application has a server you control ExamplesA SaaS analytics service, ERP synchronization on your server, a chat assistant with its own backend How the application proves its identityclient_secret in the server-side POST /v1/connect/token request
TypePublic When to chooseAll the code runs on the user's device, with nowhere to hide a secret ExamplesA mobile application, a desktop program, a single-page web application without a backend How the application proves its identityPKCE instead of a secret — Public client: the PKCE flow

To change the type, register a new client.

Quick start

The scenario for a confidential client. The application is already registered in the Connect dashboard and has a client_id, a client_secret and the registered redirect address https://yourapp.com/callback.

Step 1. Send the user to the consent page with a link. state is a random string the server keeps until the user returns:

https://vibecode.bitrix24.com/v1/connect/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=https://yourapp.com/callback&scope=crm%20task&state=abc123random

Step 2. After consent the user returns to https://yourapp.com/callback?code=AUTH_CODE_HERE&state=abc123random. Verify state and exchange the code for a key with a server-side request:

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=AUTH_CODE_HERE \
  -d redirect_uri=https://yourapp.com/callback

The key arrives in the api_key field, the Bitrix24 account in the portal.domain field. All response fields are on the POST /v1/connect/token page.

Step 3. Call the Vibecode API with the received key:

Terminal
curl -H "X-Api-Key: vibe_api_..." \
  "https://vibecode.bitrix24.com/v1/deals?limit=10"

Full example

An Express server walks the user through the whole flow: the "Connect Bitrix24" button → the consent page → code-for-key exchange → API calls on the user's behalf.

Before running it:

  1. Put the application's client_id and client_secret into the PARTNER_CLIENT_ID and PARTNER_CLIENT_SECRET environment variables.
  2. Register the redirect address https://yourapp.com/callback for the application.
  3. Plug in your own db, encrypt and decrypt implementations — the connection storage and key encryption.
javascript
import express from 'express'
import crypto from 'node:crypto'

const app = express()
const sessions = new Map() // in production — Redis or a database

const CLIENT_ID = process.env.PARTNER_CLIENT_ID
const CLIENT_SECRET = process.env.PARTNER_CLIENT_SECRET
const REDIRECT_URI = 'https://yourapp.com/callback'

// 1. The "Connect Bitrix24" button leads here
app.get('/connect', (req, res) => {
  const state = crypto.randomBytes(16).toString('hex')
  sessions.set(state, { userId: req.user.id, createdAt: Date.now() })

  const params = new URLSearchParams({
    client_id: CLIENT_ID,
    redirect_uri: REDIRECT_URI,
    scope: 'crm task',
    state,
  })
  res.redirect(`https://vibecode.bitrix24.com/v1/connect/authorize?${params}`)
})

// 2. Vibecode returns the user here after consent or decline
app.get('/callback', async (req, res) => {
  const { code, state, error } = req.query

  const session = sessions.get(state)
  if (!session) return res.status(400).send('Unknown state')
  sessions.delete(state)

  if (error === 'access_denied') {
    return res.redirect('/dashboard?connect=denied')
  }

  // 3. Exchange the code for an API key — a server-side request with client_secret
  const tokenRes = 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: CLIENT_ID,
      client_secret: CLIENT_SECRET,
      code,
      redirect_uri: REDIRECT_URI,
    }),
  })
  const data = await tokenRes.json()

  if (!tokenRes.ok) {
    // The error arrives in RFC 6749 form: { error, error_description }
    return res.status(400).send(`Exchange error: ${data.error}`)
  }

  // 4. Store the binding: our service's user ↔ Bitrix24 account
  await db.connections.upsert({
    userId: session.userId,
    portalDomain: data.portal.domain,
    portalName: data.portal.name,
    apiKey: encrypt(data.api_key), // a secret, encrypt before storing
    scopes: data.granted_scopes ?? data.scopes,
  })

  res.redirect('/dashboard?connect=ok')
})

// 5. From here on, use the stored key for calls on the user's behalf
async function listDeals(userId) {
  const connection = await db.connections.findByUserId(userId)
  const apiKey = decrypt(connection.apiKey)

  const res = await fetch('https://vibecode.bitrix24.com/v1/deals?limit=10', {
    headers: { 'X-Api-Key': apiKey },
  })
  return res.json()
}

What matters in the example:

  • state is created on the server and verified on return. Without this check an attacker can slip someone else's code to the user.
  • client_secret is kept only on the server and never reaches the browser.
  • The API key is encrypted before it is written to the database and decrypted only at the moment of a call.
  • The key's scopes come from granted_scopes. The field may be absent, in which case rely on scopes.
  • On error=access_denied the user sees a clear message rather than an exchange error page. For all refusal reasons, see GET /v1/connect/authorize.

Using the API key

The received key is of type APP and works like a standard Vibecode API key: pass it in the X-Api-Key header. The Authorization: Bearer header is not needed.

The key works with any Vibecode API endpoint within the confirmed scopes: deal lists, batch requests, aggregation and so on. Its prefix tells it apart at a glance: a partner key starts with vibe_api_. An OAuth application key from the Vibecode catalog starts with vibe_app_ and, unlike a partner key, requires a user session.

The key's scopes are exactly those the user confirmed. Platform scopes are not added to the set on their own. If you need the AI Router (/v1/chat/completions), request vibe:ai together with the other scopes, otherwise the call returns 403. To obtain platform scopes, see Platform scopes.

For a partner key, vibe:ai grants access to models only. The /v1/ai/providers, /v1/ai/credentials and /v1/ai/credentials/* routes return 403 INSUFFICIENT_SCOPE: such an application cannot manage external model keys. Neither changing the scopes nor the user consenting again lifts this refusal. Model calls with the same key work.

AI approval by the Bitrix24 account administrator. When AI approval by account administrators is enabled on the platform, an administrator approves AI for the application in the Bitrix24 account — on the consent page or at an employee's request. Until it is enabled, any employee who confirms access approves AI for the application. With approval enabled, these rules apply:

  • The application requests vibe:ai, the user confirming is not an administrator, and the Bitrix24 account has no approval — the consent page refuses with CONNECT_AI_ADMIN_REQUIRED and offers to ask an administrator. After the request, redirect_uri receives error=access_denied with error_description=admin_approval_requested.
  • While there is no approval, or after an administrator revokes it, the model routes (/v1/chat/completions, /v1/embeddings, /v1/models and others) return 403 CONNECT_AI_NOT_PERMITTED. The key's other scopes work.
  • The key does not need to be reissued: once an administrator approves AI, the same key regains access to the models.

Available scopes

When calling /v1/connect/authorize, pass the same scopes as when creating a standard API key in a Bitrix24 account. Their list is in the Keys and authorization section, and it grows as new Bitrix24 modules appear. On the consent page the user confirms the list as a whole: an individual item cannot be removed, only "Allow" and "Deny" are available. The requested set arrives in the scopes field of the /v1/connect/token response, the final one in the granted_scopes field.

Vibecode platform scopes fall into three groups: the application requests vibe:ai itself, vibe:search, vibe:infra, vibe:feedback and vibe:connectors are granted by a platform administrator, and vibe:storage and vibe:artifacts are not granted to a Connect application: a platform administrator can grant vibe:storage in COMPANY mode only, and vibe:artifacts is granted in no mode. For the procedure, see Platform scopes.

A machine-readable list of the scopes an application can request on its own is served in the scopes_supported field of the /.well-known/oauth-authorization-server document (RFC 8414). Scopes an administrator granted to a specific application do not appear in this document.

Security

  • state — a cryptographically strong random string per request that the application verifies on return to redirect_uri. Protects against CSRF.
  • client_secret — server only. The secret never reaches a browser, a mobile application or client-side code. The code-for-key exchange is done by a server-side request.
  • Key storage. The API key grants access to the user's data. Store it encrypted, restrict access to the connection record and do not write the key to logs.
  • redirect_uri matches character for character. The value in /v1/connect/authorize and /v1/connect/token must be identical, otherwise the exchange returns invalid_grant.

Endpoint reference

Method Path Description
MethodGET Path/v1/connect/authorize DescriptionFlow start: redirect to the consent page
MethodPOST Path/v1/connect/token DescriptionExchange a one-time code for a permanent API key and poll a device sign-in
MethodPOST Path/v1/connect/device/authorize DescriptionConfirmation code for signing in from a device without a browser
MethodPOST Path/v1/connect/revoke DescriptionRevocation of a single key by the application itself
MethodGET Path/v1/connect/company/status DescriptionDiagnostics of your own Company connection

Error codes

Working calls through a Company connection receive 503 ADMIN_CHECK_REQUIRED with Retry-After: 30 while the holder check is unconfirmed. Retry after 30 seconds.

The /v1/connect/authorize, /v1/connect/token and /v1/connect/device/authorize endpoints return errors in RFC 6749 form — { error, error_description }, without the success wrapper. /v1/connect/revoke responds in the same form per RFC 7009. 409 refusals from revoke and client refusals in COMPANY mode also carry a code field. A /v1/connect/authorize refusal after redirect_uri is validated arrives as a redirect to that address.

error When it occurs
errorinvalid_request When it occursA required parameter is missing or malformed
errorinvalid_client When it occursThe client is unknown or disabled, or the secret does not match
errorinvalid_grant When it occursThe authorization code has expired, has already been used, or redirect_uri does not match
errorunsupported_grant_type When it occursgrant_type in /v1/connect/token is missing or not supported
errorunauthorized_client When it occursDevice sign-in is not allowed for this client
errorinvalid_scope When it occursA scope outside the client's registered set was requested
erroraccess_denied When it occursThe user declined access or the key could not be issued — the reason is in error_description
errortemporarily_unavailable When it occursKey issuance did not complete due to temporary unavailability, and the attempt can be retried. The reason is in error_description

Full tables with conditions are in the "Errors" section of each endpoint page. GET /v1/connect/company/status responses come in the common API envelope — { "success": false, "error": { "code", "message" } }.

Rate limit exceeded — 429, in two forms. The endpoint's own limiter responds in the common API envelope with the RATE_LIMITED code and sets X-RateLimit-* headers. The platform's entry-point limiter on /v1/connect/token and device sign-in polling responds in RFC 6749 form with error=slow_down and without X-RateLimit-* headers. Tell them apart by the X-RateLimit-Limit header.

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

See also