## Create an end-to-end analytics source

`POST /v1/crm-tracking/sources`

Creates a custom end-to-end analytics source in your Bitrix24 account. Send fields at the JSON root, without a wrapper object.

> **The method ships in the `crm 26.2100.0` update and is not yet available on all Bitrix24 accounts.** Until the feature is enabled for your Bitrix24 account, the API returns `422 METHOD_NOT_YET_AVAILABLE`.

Requires the `crm` scope and a key that permits writes.

## Request body fields

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `name` | string | yes | Source name |
| `color` | string | no | Source color in `#rgb` or `#rrggbb` format |
| `refDomains` | string[] | no | List of referring domains |
| `utmSources` | string[] | no | List of `utm_source` values |

The body accepts no other fields. Bitrix24 trims whitespace, removes empty values, and limits each list to 100 values. The API validates the shape: an array of strings.

## Examples

### curl — personal key

```bash

curl -X POST "https://vibecode.bitrix24.com/v1/crm-tracking/sources" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Partner campaign",
  "color": "#55d0e0",
  "refDomains": [
    "partner.example.com"
  ],
  "utmSources": [
    "partner"
  ]
}'

```

### curl — OAuth application

```bash

curl -X POST "https://vibecode.bitrix24.com/v1/crm-tracking/sources" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Partner campaign",
  "color": "#55d0e0",
  "refDomains": [
    "partner.example.com"
  ],
  "utmSources": [
    "partner"
  ]
}'

```

### JavaScript — personal key

```javascript

const res = await fetch('https://vibecode.bitrix24.com/v1/crm-tracking/sources', {

  method: 'POST',

  headers: {
    "X-Api-Key": "YOUR_API_KEY",
    "Content-Type": "application/json"
  },

  body: JSON.stringify({
    "name": "Partner campaign",
    "color": "#55d0e0",
    "refDomains": [
      "partner.example.com"
    ],
    "utmSources": [
      "partner"
    ]
  }),

})

const { success, data } = await res.json()

console.log(data.id)

```

### JavaScript — OAuth application

```javascript

const res = await fetch('https://vibecode.bitrix24.com/v1/crm-tracking/sources', {

  method: 'POST',

  headers: {
    "X-Api-Key": "YOUR_APP_KEY",
    "Authorization": "Bearer USER_SESSION_TOKEN",
    "Content-Type": "application/json"
  },

  body: JSON.stringify({
    "name": "Partner campaign",
    "color": "#55d0e0",
    "refDomains": [
      "partner.example.com"
    ],
    "utmSources": [
      "partner"
    ]
  }),

})

const { success, data } = await res.json()

console.log(data.id)

```

## Response fields

HTTP `201` on creation.

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on success |
| `data` | object | Creation result |
| `data.id` | number | Source ID for [reading](/docs/entities/crm-tracking/sources-get) |

## Response example

Response shape example, not a live call result.

```json

{
  "success": true,
  "data": {
    "id": 2
  }
}

```

## Error response example

400 — missing name:

```json

{
  "success": false,
  "error": {
    "code": "MISSING_REQUIRED_FIELDS",
    "message": "name is required"
  }
}

```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `MISSING_REQUIRED_FIELDS` | `name` is missing |
| 400 | `INVALID_PARAMS` | The body is not an object, carries a field not listed above, `name` is not a string, `color` is not in `#rgb` or `#rrggbb` format, or `refDomains` or `utmSources` is not an array of strings. `message` names the cause |
| 400 | `UNKNOWN_FILTER_FIELD` | A query parameter was supplied |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key permits reads only |
| 403 | `SCOPE_DENIED` | The `crm` scope is missing |
| 401 | `TOKEN_MISSING` | No credentials are configured for the key |
| 422 | `METHOD_NOT_YET_AVAILABLE` | The feature is not enabled for the portal yet |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 returned an invalid response |

Bitrix24 refusals retain their code and message. For common errors, see [Errors](/docs/errors).

## See also

- [List sources](/docs/entities/crm-tracking/sources-list)

- [Get a source](/docs/entities/crm-tracking/sources-get)

- [Update a source](/docs/entities/crm-tracking/sources-update)
