## Search inventory document items

`POST /v1/catalog-document-elements/search`

Searches inventory document items using conditions passed in the request body.

Returns the same records as [`GET /v1/catalog-document-elements`](/docs/entities/catalog-document-elements/list), but conditions are passed as a JSON object rather than a query string: lists of values with `$in`, ranges with `$gte` and `$lte`, and several conditions at once.

## Request fields (body)

| Field | Type | Default | Description |
|------|-----|-----------|---------|
| `filter` | object | — | Filter by fields from `GET /v1/catalog-document-elements/fields`.<br>[Filtering syntax](/docs/filtering). Example: `{"docId": {"$in": [75, 79]}}` — items of two documents, `docId` comes from [`GET /v1/catalog-documents`](/docs/entities/catalog-documents/list) |
| `select` | string[] | — | Response fields: `["id", "docId", "amount"]`. A comma-separated string is also accepted: `"id,docId,amount"`. The `id` field is always returned. Names come from [`GET /v1/catalog-document-elements/fields`](/docs/entities/catalog-document-elements/fields) |
| `sort` | string \| object \| string[] | — | Sorting: `"-id"` — descending, `"amount"` — ascending. An object `{"amount": "desc"}` and an array of strings `["-amount", "id"]` are also accepted, as is the field name `order` instead of `sort` |
| `limit` | number | `50` | Number of records, from 1 to 5000 |
| `offset` | number | `0` | Number of records to skip from the start of the result set |

When `limit` is greater than 50, Vibecode assembles the response from several pages automatically. Request the next page with `offset` while `meta.hasMore` is `true`.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-document-elements/search" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "docId": { "$in": [75, 79] } },
    "select": ["id", "docId", "elementId", "amount", "storeTo"],
    "sort": "-id",
    "limit": 10
  }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-document-elements/search" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "docId": { "$in": [75, 79] } },
    "select": ["id", "docId", "elementId", "amount", "storeTo"],
    "sort": "-id",
    "limit": 10
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-document-elements/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { docId: { $in: [75, 79] } },
    select: ['id', 'docId', 'elementId', 'amount', 'storeTo'],
    sort: '-id',
    limit: 10,
  }),
})

const { success, data, meta } = await res.json()
console.log('Items found:', meta.total)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-document-elements/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { docId: { $in: [75, 79] } },
    select: ['id', 'docId', 'elementId', 'amount', 'storeTo'],
    sort: '-id',
    limit: 10,
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | array | Array of items. With `select` set — only the listed fields and `id` |
| `data[].id` | number | Item ID |
| `data[].docId` | number | Inventory document ID. Document — [`GET /v1/catalog-documents/:id`](/docs/entities/catalog-documents/get) |
| `data[].elementId` | number | Product ID. Product — [`GET /v1/catalog-products/:id`](/docs/entities/catalog-products/get) |
| `data[].amount` | number \| null | Product quantity, `null` — not set |
| `data[].purchasingPrice` | number \| null | Purchase price per unit, `null` — not set |
| `data[].storeFrom` | number \| null | Source warehouse, `null` — no warehouse set. Warehouses — [`GET /v1/warehouses`](/docs/entities/warehouses/list) |
| `data[].storeTo` | number \| null | Destination warehouse, `null` — no warehouse set. Warehouses — [`GET /v1/warehouses`](/docs/entities/warehouses/list) |
| `meta.total` | number | Total number of items matching the filter |
| `meta.hasMore` | boolean | Whether there are more items beyond `limit` |
| `meta.durationMs` | number | Request duration in milliseconds |
| `meta.warnings` | array | Request warnings, each with the fields `code`, `message`, `field`. Returned when `select` contains a name that is not in the schema — code `UNKNOWN_SELECT_FIELD` |

## Response example

```json
{
  "success": true,
  "data": [
    {
      "id": 27,
      "docId": 75,
      "elementId": 6907,
      "amount": 5,
      "storeTo": 1
    },
    {
      "id": 21,
      "docId": 79,
      "elementId": 6907,
      "amount": 5,
      "storeTo": 3
    }
  ],
  "meta": {
    "total": 2,
    "hasMore": false,
    "durationMs": 138
  }
}
```

## Error response example

400 — filter by a field that is not in the item schema:

```json
{
  "success": false,
  "error": {
    "code": "UNKNOWN_FILTER_FIELD",
    "message": "Unknown filter field 'bogus' for entity 'catalog-document-elements'. Available: id, docId, elementId, amount, purchasingPrice, storeFrom, storeTo"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `UNKNOWN_FILTER_FIELD` | Filter by a field that is not in the schema. The message lists the allowed fields |
| 400 | `UNKNOWN_SORT_FIELD` | Sorting by a field that is not in the schema. The message lists the allowed fields |
| 400 | `INVALID_FILTER_OPERATOR` | The filter contains an unsupported operator. The message lists the supported ones |
| 400 | `INVALID_LIMIT` | `limit` is not a number, for example the string `"abc"` |
| 400 | `INVALID_SELECT_TYPE` | `select` is neither a string nor an array of strings |
| 400 | `INVALID_SORT_TYPE` | `sort` is not a string, an object, or an array of strings |
| 400 | `INVALID_REQUEST` | The request body is not a JSON object, for example an array |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |
| 401 | `INVALID_API_KEY` | The API key passed was not found |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |
| 403 | `SCOPE_DENIED` | The API key does not have the `catalog` scope |
| 429 | `RATE_LIMITED` | Rate limit exceeded: 300 requests per minute per portal, all API keys of the portal share one 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 items](/docs/entities/catalog-document-elements/list)
- [Get an item](/docs/entities/catalog-document-elements/get)
- [Item fields](/docs/entities/catalog-document-elements/fields)
- [Inventory document items](/docs/entities/catalog-document-elements)
- [Search inventory documents](/docs/entities/catalog-documents/search)
- [Filtering syntax](/docs/filtering)
- [Limits and optimization](/docs/optimization)
