## Bind a knowledge base to a menu

`POST /v1/sites/:id/menu-bindings`

Binds a knowledge base site to a Bitrix24 menu by the menu's internal code, and that menu changes for all employees of the Bitrix24 account.

Site type restrictions and how a binding changes the employees' menu are covered in [Knowledge base menu bindings](/docs/entities/sites/menu-bindings).

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `id` (path) | number | yes | Knowledge base site ID. List: `GET /v1/sites?scope=KNOWLEDGE` |
| `scope` (query) | string | no | Site scope: `KNOWLEDGE`, `GROUP` or `MAINPAGE`. A knowledge base site is found even without this parameter |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `menuCode` | string | yes | Internal menu code, for example `crm_switcher:lead`. Codes already in use on the Bitrix24 account: `GET /v1/sites/menu-bindings` |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/sites/235/menu-bindings" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"menuCode": "crm_switcher:lead"}'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/sites/235/menu-bindings" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"menuCode": "crm_switcher:lead"}'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/sites/235/menu-bindings', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ menuCode: 'crm_switcher:lead' }),
})

const { success, data } = await res.json()
console.log(data[0].publicUrl)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/sites/235/menu-bindings', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ menuCode: 'crm_switcher:lead' }),
})

const { success, data } = await res.json()
console.log(data[0].publicUrl)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | array | Bindings of this site to the given menu code, read back after the write |
| `data[].siteId` | number | Site ID |
| `data[].menuCode` | string | Menu code |
| `data[].title` | string | Site title. Empty string if the title was not returned |
| `data[].publicUrl` | string | Public URL of the site. Empty string if the URL was not returned |

## Response example

```json
{
  "success": true,
  "data": [
    {
      "siteId": 235,
      "menuCode": "crm_switcher:lead",
      "title": "VIBE-PROBE",
      "publicUrl": "https://example.bitrix24.com/knowledge/vibe-probe-bind/"
    }
  ]
}
```

## Error response example

404 — site not found:

```json
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "Site not found or not visible"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `MISSING_REQUIRED_FIELDS` | The body has no `menuCode` field or the body is not an object |
| 400 | `INVALID_PARAMS` | The body has fields other than `menuCode` — message `Only menuCode is accepted` |
| 400 | `INVALID_PARAMS` | `menuCode` is empty, whitespace only or not a string |
| 400 | `INVALID_PARAMS` | `id` in the path is not a positive integer |
| 400 | `INVALID_SCOPE` | `scope` is not `KNOWLEDGE`, `GROUP` or `MAINPAGE` |
| 404 | `ENTITY_NOT_FOUND` | No site with this `id` was found among knowledge bases, workgroup sites and sites in the given `scope` — message `Site not found or not visible` |
| 409 | `SITE_BINDING_TYPE_MISMATCH` | The site is not a knowledge base: a regular site or a site bound to a workgroup. A workgroup binding changes the site type to `GROUP` |
| 409 | `LANDING_MODULE_NOT_ENABLED` | The Sites module is unavailable on the portal. Ask the portal administrator to enable it — while the module is off, a retry returns the same rejection |
| 422 | `BITRIX_ERROR` | Bitrix24 rejected the binding. `message` lists possible causes: the site is unavailable, not a knowledge base, no write permission, the binding already exists |
| 422 | `BITRIX_ERROR` | The binding was created, but Bitrix24 returned the bindings list in an unexpected format |
| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 denied access to the key owner |
| 403 | `B24_TARIFF_RESTRICTION` | The portal plan does not allow the call |
| 403 | `SCOPE_DENIED` | The API key does not have the `landing` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode, the request does not reach Bitrix24 |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |
| 429 | `RATE_LIMITED` | Bitrix24 throttled requests to the portal. Retry after the delay given in the `Retry-After` header |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 returned a server error or the connection dropped before the full response. The operation may have succeeded — read the bindings back before retrying |
| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond in time. The operation may have succeeded — read the bindings back before retrying |

Full list of common API errors — [Errors](/docs/errors).

## See also

- [Knowledge base menu bindings](/docs/entities/sites/menu-bindings)
- [List knowledge base menu bindings](/docs/entities/sites/menu-bindings/list)
- [Unbind a knowledge base from a menu](/docs/entities/sites/menu-bindings/unbind)
- [Knowledge base workgroup bindings](/docs/entities/sites/group-binding)
- [List sites](/docs/entities/sites/list)
- [Errors](/docs/errors)
