For AI agents: markdown of this page — /docs-content-en/entities/contacts/companies-create.md documentation index — /llms.txt
Link a company to a contact
POST /v1/contacts/:id/companies
Links one company to a contact; the contact's other companies stay linked.
To replace the whole set of companies in one call, use PUT /v1/contacts/:id/companies.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
Parameterid (path) |
Typenumber | Requiredyes | DescriptionContact ID. List: GET /v1/contacts |
Request fields (body)
| Field | Type | Required | Description |
|---|---|---|---|
FieldcompanyId |
Typenumber | Requiredyes | DescriptionCompany ID. List: GET /v1/companies. A string of digits is accepted too, for example "3101" |
FieldisPrimary |
Typeboolean | Requiredno | DescriptionMake the company primary. The previous primary company loses the flag. The contact's first company becomes primary regardless of the value |
Fieldsort |
Typenumber | Requiredno | DescriptionThe company's position in the list. If omitted, the binding goes to the end of the list |
Examples
curl — personal key
curl -X POST "https://vibecode.bitrix24.com/v1/contacts/2943/companies" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "companyId": 3101, "isPrimary": true, "sort": 20 }'
curl — OAuth application
curl -X POST "https://vibecode.bitrix24.com/v1/contacts/2943/companies" \
-H "X-Api-Key: YOUR_APP_KEY" \
-H "Authorization: Bearer USER_SESSION_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "companyId": 3101, "isPrimary": true, "sort": 20 }'
JavaScript — personal key
const res = await fetch('https://vibecode.bitrix24.com/v1/contacts/2943/companies', {
method: 'POST',
headers: {
'X-Api-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({ companyId: 3101, isPrimary: true, sort: 20 }),
})
const { success, data } = await res.json()
console.log('Companies linked to the contact:', data.length)
JavaScript — OAuth application
const res = await fetch('https://vibecode.bitrix24.com/v1/contacts/2943/companies', {
method: 'POST',
headers: {
'X-Api-Key': 'YOUR_APP_KEY',
'Authorization': 'Bearer USER_SESSION_TOKEN',
'Content-Type': 'application/json',
},
body: JSON.stringify({ companyId: 3101, isPrimary: true, sort: 20 }),
})
const { success, data } = await res.json()
Response fields
| Field | Type | Description |
|---|---|---|
Fieldsuccess |
Typeboolean | DescriptionAlways true on success |
Fielddata |
Typearray | DescriptionAll of the contact's bindings after linking, in sort order |
Fielddata[].companyId |
Typenumber | DescriptionCompany ID. Get the company: GET /v1/companies/:id |
Fielddata[].isPrimary |
Typeboolean | DescriptionThe contact's primary company. true on exactly one binding |
Fielddata[].sort |
Typenumber | DescriptionThe company's position in the list |
Fielddata[].roleId |
Typenumber | DescriptionBinding role. The binding methods do not save it |
Response example
A second company is linked to a contact that has one company, and the new one becomes primary:
{
"success": true,
"data": [
{ "companyId": 3099, "sort": 10, "isPrimary": false, "roleId": 0 },
{ "companyId": 3101, "sort": 20, "isPrimary": true, "roleId": 0 }
]
}
Error response example
409 — the company is already linked to this contact:
{
"success": false,
"error": {
"code": "RELATION_ALREADY_EXISTS",
"message": "This binding already exists"
}
}
Errors
| HTTP | Code | Description |
|---|---|---|
| HTTP400 | CodeINVALID_PARAMS |
Descriptionid is not a positive integer |
| HTTP400 | CodeMISSING_REQUIRED_FIELDS |
DescriptioncompanyId is not passed or cannot be converted to a positive integer, for example "abc" or 0 |
| HTTP404 | CodeENTITY_NOT_FOUND |
DescriptionThere is no contact with this id |
| HTTP409 | CodeRELATION_ALREADY_EXISTS |
DescriptionThe company is already linked to this contact |
| HTTP401 | CodeMISSING_API_KEY |
DescriptionThe X-Api-Key header is missing |
| HTTP401 | CodeTOKEN_MISSING |
DescriptionNo Bitrix24 tokens are attached to the key |
| HTTP403 | CodeSCOPE_DENIED |
DescriptionThe key lacks the crm scope |
| HTTP403 | CodeWRITE_BLOCKED_READONLY_KEY |
DescriptionThe key is in read-only mode. Linking requires a key with write access |
| HTTP429 | CodeRATE_LIMITED |
DescriptionRate limit exceeded. Retry after the delay in the Retry-After header |
| HTTP502 | CodeBITRIX_UNAVAILABLE |
DescriptionBitrix24 is unavailable. Retry the request later |
Full list of common API errors — Errors.
Known specifics
- Company existence is not checked. An ID that does not belong to any company is linked without an error and appears in the contact's list of bindings. Before linking, check the company with
GET /v1/companies/:id. - The role is not saved. The
roleIdfield in the body is accepted without an error but is not saved: in the response, the new binding hasroleIdequal to0. - Change the primary company or the order. For companies that are already linked, use
PUT /v1/contacts/:id/companiesand pass the whole required set initems: companies not passed are unlinked.