## Search shipments

`POST /v1/shipments/search`

Searches online store order shipments with filtering, sorting, and automatic pagination. Parameters are passed in the body of the POST request. Suited to complex filters and wide date ranges. For simple selections of up to 5000 records, the shipment list is enough.

## Request fields (body)

| Field | Type | Default | Description |
|------|-----|-----------|---------|
| `filter` | object | — | Filtering by the fields from `GET /v1/shipments/fields`.<br>[Filtering syntax](/docs/filtering). Example: `{ "orderId": 1027, "deducted": false }` |
| `select` | string[] | — | Field selection: `["id", "orderId", "deliveryName", "priceDelivery", "trackingNumber"]`. A comma-separated string is also accepted. An unknown field does not cause an error: it is absent from the `data` items, and `meta.warnings` carries an `UNKNOWN_SELECT_FIELD` warning with the field name in `field` |
| `sort` | string | — | Sorting via the short syntax: `"-id"`, the minus means descending |
| `order` | object | — | Sorting as an object: `{ "id": "desc" }`. If `sort` is also passed, `sort` takes effect |
| `limit` | number | `50` | Number of records, up to 5000 |
| `offset` | number | `0` | Skip N records. Rejected when combined with a date range filter wider than 14 days — see `UNSTABLE_OFFSET_PAGINATION` in the "Errors" section |
| `autoWindow` | boolean | `true` | Split the selection into weekly windows when filtering by a date range wider than 14 days. `false` disables splitting |
| `withTotal` | boolean | — | Whether to return the record count in `meta.total`. Details — [Paging and record counts](/docs/entity-api#paging-and-record-counts) |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/shipments/search" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "orderId": 1027, "deducted": false },
    "select": ["id", "orderId", "deliveryName", "priceDelivery", "trackingNumber"],
    "sort": "-id",
    "limit": 10
  }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/shipments/search" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "orderId": 1027, "deducted": false },
    "select": ["id", "orderId", "deliveryName", "priceDelivery", "trackingNumber"],
    "sort": "-id",
    "limit": 10
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/shipments/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { orderId: 1027, deducted: false },
    select: ['id', 'orderId', 'deliveryName', 'priceDelivery', 'trackingNumber'],
    sort: '-id',
    limit: 10,
  }),
})

const { success, data, meta } = await res.json()
console.log('Not marked as shipped:', data.length)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/shipments/search', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { orderId: 1027, deducted: false },
    select: ['id', 'orderId', 'deliveryName', 'priceDelivery', 'trackingNumber'],
    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 shipments. All fields — [Shipment fields](/docs/entities/shipments/fields) |
| `meta.total` | number | How many records matched the filter. May be absent — see the `withTotal` field |
| `meta.hasMore` | boolean | Whether there are more records beyond `limit` |
| `meta.durationMs` | number | Request duration in milliseconds |
| `meta.autoWindowed` | boolean | `true` if the selection was split into time windows |
| `meta.windowCount` | number | Number of windows. Arrives with `autoWindowed: true` |
| `meta.windowErrors` | number | How many windows ended with an error. Arrives if some of the windows failed |
| `meta.windowErrorSample` | object | Error code and message of the first failed window. Arrives together with `windowErrors` |
| `meta.batchWaves` | number | Number of waves of parallel requests. Arrives with `autoWindowed: true` |
| `meta.warnings` | array | Warnings about request parameters: `code`, `message`, `field`. Arrives only when there are warnings |
| `meta.pageErrorSample` | object | Code and message of the error that stopped automatic pagination early. Arrives only if `data` holds fewer records than `limit` |

## Response example

A request with `select` returns only the listed fields:

```json
{
  "success": true,
  "data": [
    {
      "id": 1205,
      "orderId": 1027,
      "deliveryName": "Courier delivery",
      "priceDelivery": 500,
      "trackingNumber": "VIBE-DOC-1"
    }
  ],
  "meta": {
    "total": 1,
    "hasMore": false,
    "durationMs": 278
  }
}
```

## Error response example

400 — filter by a nonexistent field:

```json
{
  "success": false,
  "error": {
    "code": "UNKNOWN_FILTER_FIELD",
    "message": "Unknown filter field 'unknownField' for entity 'shipments'. Available: accountNumber, allowDelivery, basePriceDelivery, canceled, comments, companyId, currency, customPriceDelivery, dateAllowDelivery, dateCanceled, dateDeducted, dateInsert, dateMarked, dateResponsibleId, deducted, deliveryDocDate, deliveryDocNum, deliveryId, deliveryName, deliveryXmlId, discountPrice, empAllowDeliveryId, empCanceledId, empDeductedId, empMarkedId, empResponsibleId, externalDelivery, id, id1c, marked, orderId, priceDelivery, reasonMarked, reasonUndoDeducted, responsibleId, statusId, statusXmlId, system, trackingDescription, trackingLastCheck, trackingNumber, trackingStatus, updated1c, version1c, xmlId, shipmentItems"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `UNKNOWN_FILTER_FIELD` | Filter by a field that is not in the schema. Field list: [`GET /v1/shipments/fields`](/docs/entities/shipments/fields) |
| 400 | `INVALID_FILTER_FIELD` | The field name in the filter starts with the unsupported prefix `@` or `!@` |
| 400 | `INVALID_FILTER_OPERATOR` | Unknown filter operator, an empty object as a condition value, or the logical condition `$or` |
| 400 | `INVALID_FILTER_SHAPE` | `filter` is not an object of conditions, for example a string, number, or array |
| 400 | `INVALID_DUPLICATE_FILTER_FIELD` | Two filter conditions reduce to one Bitrix24 condition, for example `$ne` and `$nin` on the same field. Pass only one of them |
| 400 | `UNKNOWN_SORT_FIELD` | Sorting by a field that is not in the schema or cannot be sorted on |
| 400 | `INVALID_SORT_TYPE` | `sort` or `order` is passed as a value of an unsuitable type, for example a number |
| 400 | `INVALID_SORT_DIRECTION` | The direction in `order` is not one of `asc`, `desc`, `ASC`, `DESC`, `1`, `-1` |
| 400 | `INVALID_LIMIT` | `limit` is not a number |
| 400 | `INVALID_SELECT_TYPE` | `select` is not a string or an array of strings |
| 400 | `INVALID_REQUEST` | The request body is not a JSON object |
| 400 | `UNSTABLE_OFFSET_PAGINATION` | `offset` greater than zero together with a filter by a date range wider than 14 days. Fetch everything in one request with `limit` up to 5000, or pass `autoWindow: false` with sorting by `id`, or split the date range into parts yourself |
| 403 | `SCOPE_DENIED` | The API key does not have the `sale` scope |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |
| 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 exact value arrives in the `x-ratelimit-limit` header (the cap is divided across replicas). Retry after the delay in the `Retry-After` header |

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

## Known specifics

**Splitting into time windows.** A filter by a date field (`dateInsert`, `dateDeducted`, `dateAllowDelivery`, and others) with a range wider than 14 days is split into weekly windows that run in parallel waves. This lets the selection get past the cap of 5000 records per call.

**A partial window failure does not abort the request.** If some of the windows failed, the response arrives with `success: true` and records only from the successful windows. Before treating the selection as complete, check that `meta.windowErrors` is absent.

## See also

- [List shipments](/docs/entities/shipments/list)
- [Get a shipment](/docs/entities/shipments/get)
- [Shipment aggregation](/docs/entities/shipments/aggregate)
- [Shipment fields](/docs/entities/shipments/fields)
- [Shipments](/docs/entities/shipments)
- [Filtering syntax](/docs/filtering)
- [Entity reference](/docs/entity-api)
- [Limits and optimization](/docs/optimization)
