## Bind CRM item to task

`POST /v1/tasks/:taskId/bind-crm-item`

Binds a CRM item, such as a deal, to a task on behalf of the key's user.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `taskId` (path) | number | yes | Task ID. List: [`GET /v1/tasks`](/docs/entities/tasks/list) |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `crmItemId` | string | yes | Reference to a specific CRM item: a type prefix and an ID, for example `D_123` — the deal with ID 123. Deal IDs: [`GET /v1/deals`](/docs/entities/deals/list) |

Any field other than `crmItemId` is rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
curl -X POST 'https://vibecode.bitrix24.com/v1/tasks/289/bind-crm-item' \
  -H 'X-Api-Key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"crmItemId":"D_123"}'
```

### curl — OAuth application

```bash
curl -X POST 'https://vibecode.bitrix24.com/v1/tasks/289/bind-crm-item' \
  -H 'X-Api-Key: YOUR_APP_KEY' \
  -H 'Authorization: Bearer USER_SESSION_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"crmItemId":"D_123"}'
```

### JavaScript — personal key

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/tasks/289/bind-crm-item', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"crmItemId":"D_123"}),
})
const result = await response.json()
console.log(result.data.success)
```

### JavaScript — OAuth application

```javascript
const response = await fetch('https://vibecode.bitrix24.com/v1/tasks/289/bind-crm-item', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"crmItemId":"D_123"}),
})
const result = await response.json()
console.log(result.data.success)
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on success |
| `data` | object | Binding result |
| `data.success` | boolean | `true` — the CRM item is bound to the task |

## Response example

```json
{
  "success": true,
  "data": {
    "success": true
  }
}
```

## Error response example

403 — Bitrix24 refused the binding:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ACCESS_DENIED",
    "message": "This action is unavailable.",
    "hint": "Bitrix24 refused this call; the cause is not determined.",
    "cause": "unknown",
    "fix": {
      "action": "none"
    }
  }
}
```

The `error.message` text comes from Bitrix24. Branch on `error.code`, not on the message text.

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | `taskId` is not a positive integer: `taskId must be a positive integer` |
| 400 | `INVALID_PARAMS` | The request body is not a JSON object: `body must be an object` |
| 400 | `INVALID_PARAMS` | The body contains fields other than `crmItemId`: `body contains unsupported fields` |
| 400 | `INVALID_PARAMS` | `crmItemId` is missing or an empty string: `crmItemId must be a non-empty string` |
| 401 | `MISSING_API_KEY` | `X-Api-Key` is missing |
| 401 | `INVALID_API_KEY` | The key is not found |
| 401 | `TOKEN_MISSING` | The key has no valid Bitrix24 token |
| 403 | `SCOPE_DENIED` | The key lacks the `task` or `tasks` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only |
| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 refused the binding: `This action is unavailable.` |
| 422 | `BITRIX_ERROR` | Bitrix24 rejected the binding for another reason |

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

## See also

- [Get task](/docs/entities/tasks/get)
- [Deals](/docs/entities/deals)
- [Tasks](/docs/entities/tasks)
