## Add expenses to an end-to-end analytics source

`POST /v1/crm-tracking/sources/:id/expenses`

Manually adds an expense pack to a source for the specified period. Send fields at the JSON root.

> **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 with `READWRITE` access.

## Parameters

| Parameter | Type | Required | Default | Description |
|----------|-----|:-----:|-----------|----------|
| `id` (path) | integer | yes | — | Positive source ID. [Source list](/docs/entities/crm-tracking/sources-list) |

Query parameters are not accepted.

## Request body fields

| Field | Type | Required | Description |
|------|-----|:-----:|----------|
| `dateFrom` | string | yes | Period start in `YYYY-MM-DD` format |
| `dateTo` | string | yes | Period end in `YYYY-MM-DD` format |
| `amount` | number | yes | Amount in currency units: `12.5` means 12.50, without conversion to minor units |
| `currencyId` | string | yes | Currency code. [Currency list](/docs/entities/currencies) |
| `actions` | integer | no | Number of actions |
| `comment` | string \| null | no | Expense comment |

Specify the source only in the path. The `sourceId` field is not accepted in the request body.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/crm-tracking/sources/2/expenses" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dateFrom":"2026-10-01","dateTo":"2026-10-07","amount":12.5,"currencyId":"USD"}'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/crm-tracking/sources/2/expenses" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"dateFrom":"2026-10-01","dateTo":"2026-10-07","amount":12.5,"currencyId":"USD"}'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/crm-tracking/sources/2/expenses', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ dateFrom: '2026-10-01', dateTo: '2026-10-07', amount: 12.5, currencyId: 'USD' })
})
const { data } = await res.json()
console.log(data.id)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/crm-tracking/sources/2/expenses', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ dateFrom: '2026-10-01', dateTo: '2026-10-07', amount: 12.5, currencyId: 'USD' })
})
const { 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 | Expense pack ID. [Expense list](/docs/entities/crm-tracking/expenses-list) |

## Response example

Response shape example.

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

## Error response example

400 — required fields are missing.

```json
{"success":false,"error":{"code":"MISSING_REQUIRED_FIELDS","message":"dateFrom, dateTo, amount and currencyId are required"}}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `MISSING_REQUIRED_FIELDS` | A required field is missing |
| 400 | `INVALID_PARAMS` | Invalid ID, date format, field type, or unknown body field |
| 400 | `UNKNOWN_FILTER_FIELD` | A query parameter was supplied |
| 403 | `SCOPE_DENIED` | The `crm` scope is missing |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key permits reads only |
| 422 | `METHOD_NOT_YET_AVAILABLE` | The feature is disabled for the Bitrix24 account or its version does not support the method |
| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 returned an invalid response |

Other Bitrix24 refusals retain their codes and messages. Secrets are removed from messages. General errors — [Errors](/docs/errors).

## Known specifics

Bitrix24 validates amount, currency, and period restrictions, including the 365-day limit. The API validates the request shape and does not impose its own bounds on these values.

## See also

- [Source list](/docs/entities/crm-tracking/sources-list)
- [Expense list](/docs/entities/crm-tracking/expenses-list)
- [Delete expenses](/docs/entities/crm-tracking/expenses-delete)
