## Search inventory documents

`POST /v1/catalog-documents/search`

Searches inventory documents using conditions specified in the request body. Use this endpoint for filters with operators and date-range queries. For simpler queries, use the list endpoint with a filter in the query string.

## Request fields (body)

| Field | Type | Default | Description |
|------|-----|-----------|---------|
| `filter` | object | — | Filter by fields listed by `GET /v1/catalog-documents/fields`.<br>[Filtering syntax](/docs/filtering). Example: `{"docType": {"$in": ["A", "S"]}, "status": "N"}` |
| `select` | string[] | — | Fields in the response: `["id", "title", "status"]`. A comma-separated string `"id,title,status"` is also accepted. Names come from [`GET /v1/catalog-documents/fields`](/docs/entities/catalog-documents/fields) |
| `sort` | string \| object \| string[] | — | Sorting: `"-id"` — descending, `"id"` — ascending, or an object `{"id": "desc"}`. Also accepted under the name `order`. If omitted, documents are sorted by `id` ascending |
| `limit` | number | `50` | Number of records, from 1 to 5000. A value above 5000 is capped at 5000 |
| `offset` | number | `0` | How many records to skip. A value above zero combined with window splitting is rejected — see `UNSTABLE_OFFSET_PAGINATION` in the "Errors" section |
| `autoWindow` | boolean | `true` | Split the search into weekly windows when filtering by a date range longer than 14 days. `false` disables splitting |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-documents/search" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "docType": "S", "status": "N" },
    "select": ["id", "title", "docType", "status", "total"],
    "sort": "-id",
    "limit": 2
  }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-documents/search" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "docType": "S", "status": "N" },
    "select": ["id", "title", "docType", "status", "total"],
    "sort": "-id",
    "limit": 2
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-documents/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { docType: 'S', status: 'N' },
    select: ['id', 'title', 'docType', 'status', 'total'],
    sort: '-id',
    limit: 2,
  }),
})

const { success, data, meta } = await res.json()
console.log(`Unposted stock adjustments returned: ${data.length}`)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-documents/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { docType: 'S', status: 'N' },
    select: ['id', 'title', 'docType', 'status', 'total'],
    sort: '-id',
    limit: 2,
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | array | Array of inventory documents (all fields — see [Inventory document fields](/docs/entities/catalog-documents/fields)). If `select` is set, only the listed fields are returned |
| `meta.total` | number | The exact number of documents matching the filter, when known. Omitted when the search across time windows is incomplete |
| `meta.hasMore` | boolean | Whether there are more documents beyond `limit` |
| `meta.durationMs` | number | Request duration in milliseconds |
| `meta.autoWindowed` | boolean | `true` if the search was split into weekly windows. Returned only when splitting occurs |
| `meta.windowCount` | number | Number of windows. Returned with `autoWindowed: true` |
| `meta.batchWaves` | number | Number of waves of parallel requests across windows. Returned with `autoWindowed: true` |
| `meta.warnings` | array | Request warnings. Returned when `select` contains an unknown document field name. The warning has code `UNKNOWN_SELECT_FIELD` and specifies the unknown name in `field`. The other fields are returned |

Use `meta.hasMore` to determine whether there are more results: a page with exactly `limit` records can still be the last page.

## Response example

```json
{
  "success": true,
  "data": [
    {
      "id": 299,
      "title": "Stock adjustment — warehouse 11",
      "docType": "S",
      "status": "N",
      "total": null
    },
    {
      "id": 151,
      "title": "stock adjustment 33",
      "docType": "S",
      "status": "N",
      "total": null
    }
  ],
  "meta": {
    "total": 36,
    "hasMore": true,
    "durationMs": 103
  }
}
```

When filtering by a date range longer than 14 days, for example `{"filter": {">=dateCreate": "2025-01-01T00:00:00Z", "<dateCreate": "2025-07-01T00:00:00Z"}}`, `meta` also contains `autoWindowed`, `windowCount` and `batchWaves`:

```json
{
  "success": true,
  "data": [
    {
      "id": 1,
      "title": "Stock adjustment #2",
      "dateCreate": "2025-01-10T11:49:37.000Z"
    },
    {
      "id": 3,
      "title": "Goods receipt #12",
      "dateCreate": "2025-06-27T05:00:47.000Z"
    }
  ],
  "meta": {
    "total": 2,
    "hasMore": false,
    "autoWindowed": true,
    "windowCount": 26,
    "batchWaves": 1,
    "durationMs": 219
  }
}
```

In the example above, all windows were read successfully and duplicates removed, so `meta.total` is the exact number of matches. The field is omitted when the search stops early at `limit` or a window returns an incomplete result. The API does not make additional requests solely to obtain a count. `data.length` is the number of returned documents; `meta.hasMore` indicates whether more results are available.

## Error response example

400 — filter by a field the document does not have:

```json
{
  "success": false,
  "error": {
    "code": "UNKNOWN_FILTER_FIELD",
    "message": "Unknown filter field 'bogus' for entity 'catalog-documents'. Available: id, docType, currency, responsibleId, status, dateStatus, createdBy, dateCreate, title, docNumber, commentary, dateDocument, siteId, total, modifiedBy, statusBy, dateModify"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `UNKNOWN_FILTER_FIELD` | Filter by a field the document does not have. The message lists the allowed fields |
| 400 | `UNKNOWN_SORT_FIELD` | Sorting by a field the document does not have. The message lists the allowed fields |
| 400 | `INVALID_FILTER_OPERATOR` | The filter contains an unsupported operator. The message lists the supported ones |
| 400 | `INVALID_SORT_TYPE` | `sort` is not a string, an object or an array of strings, for example a number |
| 400 | `INVALID_SELECT_TYPE` | `select` is not a string or an array of strings, for example a number |
| 400 | `INVALID_LIMIT` | `limit` is not a number, for example `"abc"` |
| 400 | `INVALID_REQUEST` | The request body is not a JSON object, for example an array |
| 400 | `UNSTABLE_OFFSET_PAGINATION` | `offset` is greater than zero and the filter covers a date range longer than 14 days. Fetch everything in one request with `limit` up to 5000, or pass `autoWindow: false` with `"sort": "id"`, or split the date range into parts yourself |
| 403 | `SCOPE_DENIED` | The API key does not have the `catalog` scope |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |
| 401 | `INVALID_API_KEY` | The provided API key was not found |
| 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 for the portal share this limit. The effective value is in the `x-ratelimit-limit` header. Retry after the delay in the `Retry-After` header |

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

## See also

- [List inventory documents](/docs/entities/catalog-documents/list)
- [Get an inventory document](/docs/entities/catalog-documents/get)
- [Inventory document fields](/docs/entities/catalog-documents/fields)
- [Search document items](/docs/entities/catalog-document-elements/search)
- [Inventory documents](/docs/entities/catalog-documents)
- [Filtering syntax](/docs/filtering)
- [Limits and optimization](/docs/optimization)
