
## Search invoices

`POST /v1/invoices/search`

Advanced invoice search with filtering, sorting and auto-pagination. Supports up to 5000 records.

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `filter` | object | no | Filtering. The accepted names are listed in the `400 UNKNOWN_FILTER_FIELD` error text — not every field from [`GET /v1/invoices/fields`](/docs/entities/invoices/fields) can be filtered on.<br>[Filtering syntax](/docs/filtering). Example: `"filter": { "stageId": "DT31_5:N" }` |
| `sort` | string | no | Sorting. The `-` prefix means descending. Not every field from [`GET /v1/invoices/fields`](/docs/entities/invoices/fields) can be sorted on — the accepted names are in the `400 UNKNOWN_SORT_FIELD` error text |
| `order` | object | no | Sorting as an object: `"order": { "createdTime": "desc" }`. Works the same as `sort`. When both are sent, `sort` applies |
| `limit` | number | no | Number of records (default 50, max 5000) |
| `offset` | number | no | Skip N records. Rejected when combined with a date-range filter wider than 14 days — see `UNSTABLE_OFFSET_PAGINATION` in the "Errors" section |
| `select` | string \| array | no | List of returned fields — as an array `["id", "title"]` or as a comma-separated string `"id,title"` |
| `include` | string \| array | no | Related records: `contact`, `company`, `deal` — as an array or a comma-separated string. For details of the returned data, see the "Related data" section |
| `autoWindow` | boolean | no | Split the result set into weekly windows when filtering by a date range wider than 14 days. Defaults to `true`. `false` disables splitting |

### Filter syntax

Three formats are supported:

```json
{ "filter": { ">=opportunity": 1000 } }
{ "filter": { "opportunity": { "$gte": 1000 } } }
{ "filter": { "opportunity": { ">=": 1000 } } }
```

## Examples

### curl — personal key

```bash
curl -X POST https://vibecode.bitrix24.com/v1/invoices/search \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": {
      ">=opportunity": 1000,
      "assignedById": 1
    },
    "sort": "-createdTime",
    "limit": 100
  }'
```

### curl — OAuth application

```bash
curl -X POST https://vibecode.bitrix24.com/v1/invoices/search \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": {
      ">=opportunity": 1000,
      "assignedById": 1
    },
    "sort": "-createdTime",
    "limit": 100
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/invoices/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { '>=opportunity': 1000, assignedById: 1 },
    sort: '-createdTime',
    limit: 100,
  }),
})

const { success, data, meta } = await res.json()
console.log(`Found: ${meta.total}`)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/invoices/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { '>=opportunity': 1000, assignedById: 1 },
    sort: '-createdTime',
    limit: 100,
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | array | Array of invoices. For all fields of an element, see [Invoice fields](/docs/entities/invoices/fields) |
| `meta.total` | number | Total number of records matching the filter |
| `meta.hasMore` | boolean | Whether there are more records beyond `limit` |
| `meta.durationMs` | number | Request duration in milliseconds |
| `meta.autoWindowed` | boolean | `true` if the result set was split into time windows |
| `meta.windowCount` | number | Number of windows. Present with `autoWindowed: true` |
| `meta.batchWaves` | number | Number of parallel request waves. Present with `autoWindowed: true` |

The `meta` fields sit next to `data`, not inside it. Walk through pages using `meta.hasMore`: a `data` length equal to `limit` does not rule out this being the last page.

The card URL of any invoice from the `data` array is built from its `id`:

```
https://<portal>.bitrix24.com/crm/type/31/details/<id>/
```

`31` — the `entityTypeId` of the smart invoice in Bitrix24. `<portal>` — the Bitrix24 portal domain. Access is restricted by the employee's permissions in Bitrix24.

## Related data

The `include` field accepts three values — `contact`, `company`, and `deal`:

```json
{ "limit": 10, "include": ["contact", "company", "deal"] }
```

The values are validated: any other value is rejected with `400 INVALID_INCLUDE`, and the error message lists the allowed values. Each element of the `data` array gets an `_included` block with the contact, company, and deal objects referenced by `contactId`, `companyId`, and `parentId2`. When the invoice has no such reference, `null` takes the object's place:

```json
{
  "id": 3,
  "contactId": 181,
  "companyId": 73,
  "parentId2": null,
  "_included": {
    "contact": { "id": 181 },
    "company": { "id": 73 },
    "deal": null
  }
}
```

The objects in `_included` are shortened to `id` here — the response carries every field of the record. For a general description of the mechanism, see [Related data](/docs/includes).

## Response example

```json
{
  "success": true,
  "data": [
    {
      "id": 117,
      "title": "Invoice for services",
      "stageId": "DT31_5:N",
      "opportunity": 1500,
      "currencyId": "USD",
      "assignedById": 1,
      "createdTime": "2026-08-25T08:13:37.000Z"
    }
  ],
  "meta": {
    "total": 12,
    "hasMore": false,
    "durationMs": 240
  }
}
```

With a date-range filter wider than 14 days, `meta` additionally returns `autoWindowed`, `windowCount`, and `batchWaves`:

```json
{
  "success": true,
  "data": [ /* ... */ ],
  "meta": {
    "total": 16,
    "hasMore": true,
    "autoWindowed": true,
    "windowCount": 131,
    "batchWaves": 3,
    "durationMs": 3090
  }
}
```

## Error response example

400 — filter on a field that does not exist:

```json
{
  "success": false,
  "error": {
    "code": "UNKNOWN_FILTER_FIELD",
    "message": "Unknown filter field 'nosuchfield' for entity 'invoices'. Available: id, title, stageId, categoryId, assignedById, contactId, companyId, opportunity, currencyId, begindate, closedate, accountNumber, comments, mycompanyId, sourceId, sourceDescription, xmlId, opened, isManualOpportunity, isRecurring, createdBy, createdTime, updatedTime, updatedBy, movedBy, movedTime, previousStageId, lastCommunicationTime, lastCommunicationCallTime, lastCommunicationEmailTime, lastCommunicationImolTime, lastCommunicationWebformTime"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `UNSTABLE_OFFSET_PAGINATION` | `offset` greater than zero together with a date-range filter wider than 14 days. Two different retrieval algorithms produce inconsistent results, so the request is rejected. Fetch everything in a single request with `limit` up to 5000, or pass `autoWindow: false` with sorting by `id`, or split the date range into parts yourself |
| 400 | `UNKNOWN_FILTER_FIELD` | Filter on a field the invoice does not have. The error text lists the allowed names |
| 400 | `UNKNOWN_SORT_FIELD` | Sorting on a field the invoice does not have — in `sort` or in `order`. The error text lists the allowed names |
| 400 | `INVALID_INCLUDE` | `include` carries a name the invoice does not have. The error text lists the allowed ones |
| 403 | `SCOPE_DENIED` | The API key lacks the `crm` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |
| 429 | `RATE_LIMITED` | Rate limit exceeded: 300 requests per minute per portal. All API keys of the portal share one limit. The current limit is returned in the `x-ratelimit-limit` header. Retry after the delay in the `Retry-After` header |

For the full list of common API errors, see [Errors](/docs/errors).

## Known specifics

**Time-window splitting.** A date-range filter wider than 14 days is automatically split into weekly windows executed in parallel waves, so the result set bypasses the ceiling of 5000 records per call. `meta` then returns `autoWindowed: true`, the number of windows `windowCount`, and the number of waves `batchWaves`. The `autoWindow: false` parameter disables splitting. While splitting is active, an `offset` greater than zero is rejected with `UNSTABLE_OFFSET_PAGINATION`.

## See also

- [List invoices](/docs/entities/invoices/list)
- [Invoice fields](/docs/entities/invoices/fields)
- [Batch](/docs/batch)
- [Entity API](/docs/entity-api)
