> **This method is rolling out with `crm 26.2100.0`.** It is not available on every Bitrix24 account yet. If it is not available, the API returns `422 METHOD_NOT_YET_AVAILABLE`. This is not an integration error: it means the update has not reached the account yet.

## Connect an advertising account

`POST /v1/crm-tracking/sources/:id/ad-account`

Connects an advertising account to an end-to-end analytics source and returns the resulting connection settings.

Requires the `crm` scope, a `READWRITE` key, the `crm-tracking-v3` flag enabled, and the method available in the Bitrix24 account.

## Parameters

| Parameter | Type | Required | Description |
|---|---|---|---|
| `id` (path) | number | yes | Positive integer source ID from the [sources list](/docs/entities/crm-tracking/sources-list). |

## Request body fields

| Field | Type | Required | Description |
|---|---|---|---|
| `clientId` | string | yes | Client ID from the [advertising accounts list](/docs/entities/crm-tracking/ad-account-list). |
| `accountId` | string \| null | no | Advertising account ID from the [advertising accounts list](/docs/entities/crm-tracking/ad-account-list). |

Send fields at the JSON root. Query parameters and unknown body fields are not accepted. String lengths and provider-specific requirements are validated by Bitrix24.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/crm-tracking/sources/2/ad-account" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"clientId":"DUMMY_CLIENT"}'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/crm-tracking/sources/2/ad-account" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"clientId":"DUMMY_CLIENT"}'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/crm-tracking/sources/2/ad-account', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ clientId: 'DUMMY_CLIENT' })
})
const { success, data } = await res.json()
console.log(data.sourceId)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/crm-tracking/sources/2/ad-account', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ clientId: 'DUMMY_CLIENT' })
})
const { success, data } = await res.json()
console.log(data.sourceId)
```

## Response fields

Success returns HTTP `200` with JSON.

| Field | Type | Description |
|---|---|---|
| `success` | boolean | `true` on success. |
| `data` | object | Resulting connection settings. |
| `data.sourceId` | number | Source ID from the [sources list](/docs/entities/crm-tracking/sources-list). |
| `data.provider` | string | Advertising system code. |
| `data.clientId` | string \| null | Connected client ID from the [advertising accounts list](/docs/entities/crm-tracking/ad-account-list) or `null`. |
| `data.accountId` | string \| null | Connected advertising account ID from the [advertising accounts list](/docs/entities/crm-tracking/ad-account-list) or `null`. |

## Response example

Example response structure.

```json
{
  "success": true,
  "data": {
    "sourceId": 2,
    "provider": "google",
    "clientId": "DUMMY_CLIENT",
    "accountId": null
  }
}
```

## Error response example

400 — the source does not support advertising account connections:

```json
{
  "success": false,
  "error": {
    "code": "CRM_TRACKING_AD_PROVIDER_UNSUPPORTED",
    "message": "CRM_TRACKING_AD_PROVIDER_UNSUPPORTED"
  }
}
```

## Errors

| HTTP | Code | Description |
|---|---|---|
| 400 | `MISSING_REQUIRED_FIELDS` | `clientId` is missing. |
| 400 | `INVALID_PARAMS` | Invalid ID, incorrect field type, unknown body field, or non-object body. |
| 400 | `UNKNOWN_FILTER_FIELD` | A query parameter was supplied. |
| 400 | `CRM_TRACKING_AD_PROVIDER_UNSUPPORTED` | The source does not support this advertising operation. |
| 403 | `SCOPE_DENIED` | The key lacks the `crm` scope. |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key access mode blocks writes. |
| 404 | `ENTITY_NOT_FOUND` | The specified source was not found. |
| 422 | `METHOD_NOT_YET_AVAILABLE` | The flag is off or the method is not yet available in the Bitrix24 account. |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 returned an invalid response. |

Other Bitrix24 refusal codes and messages are preserved. See [Errors](/docs/errors) for shared API errors.

## See also

- [List analytics sources](/docs/entities/crm-tracking/sources-list)
- [List advertising accounts](/docs/entities/crm-tracking/ad-account-list)
- [Get an advertising authorization URL](/docs/entities/crm-tracking/ad-account-authorization)
- [End-to-end analytics sources](/docs/entities/crm-tracking)
