## Create a shipment

`POST /v1/shipments`

Creates a shipment in an existing online store order and assigns a delivery service to it.

Fields are passed flat at the JSON root, without a `fields` wrapper.

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `orderId` | number | yes | ID of the order in which the shipment is created. List: [`GET /v1/orders`](/docs/entities/orders/list). Cannot be changed after creation |
| `deliveryId` | number | yes | Delivery service ID. List: [`GET /v1/delivery-services`](/docs/entities/delivery-services/list) |
| `allowDelivery` | boolean | no | Whether delivery is allowed. If omitted, the shipment is created with `false` |
| `statusId` | string | no | Delivery status. List: [`GET /v1/order-statuses?filter[type]=D`](/docs/entities/order-statuses/list). If omitted, the shipment gets the Bitrix24 account's initial delivery status, `DN` in the example below |
| `trackingNumber` | string | no | Tracking number |
| `deliveryDocNum` | string | no | Shipment document number |
| `deliveryDocDate` | datetime | no | Shipment document date |
| `priceDelivery` | number | no | Delivery price. If omitted, the delivery service price is used |
| `basePriceDelivery` | number | no | Base delivery price |
| `responsibleId` | number | no | ID of the responsible employee. List: [`GET /v1/users`](/docs/entities/users/list). If omitted, the responsible person is assigned automatically |
| `companyId` | number | no | CRM company ID. List: [`GET /v1/companies`](/docs/entities/companies/list). The company's existence is not checked |
| `comments` | string | no | Shipment comment |
| `xmlId` | string | no | External code. If omitted, it is generated automatically |

Full field list — [`GET /v1/shipments/fields`](./fields.md).

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/shipments" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "orderId": 1027,
    "deliveryId": 1,
    "trackingNumber": "VIBE-DOC-1",
    "comments": "Test shipment for documentation"
  }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/shipments" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "orderId": 1027,
    "deliveryId": 1,
    "trackingNumber": "VIBE-DOC-1",
    "comments": "Test shipment for documentation"
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/shipments', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    orderId: 1027,
    deliveryId: 1,
    trackingNumber: 'VIBE-DOC-1',
    comments: 'Test shipment for documentation',
  }),
})

const { success, data } = await res.json()
console.log('Shipment ID:', data.id)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/shipments', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    orderId: 1027,
    deliveryId: 1,
    trackingNumber: 'VIBE-DOC-1',
    comments: 'Test shipment for documentation',
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on success. The response HTTP status is `201` |
| `data` | object | The created shipment with all fields — [Shipment fields](./fields.md) |
| `data.id` | number | ID of the created shipment |
| `data.accountNumber` | string | Shipment number: the order number and the shipment's sequence number separated by `/` |
| `data.deducted` | boolean | The "shipped" mark. Always `false` for a new shipment |
| `data.deliveryName` | string | Name of the delivery service from `deliveryId` |
| `data.shipmentItems` | array | Shipment items. An empty array if no items have been added yet |
| `data.system` | boolean | System shipment. Always `false` for a shipment created via the API |

## Response example

```json
{
  "success": true,
  "data": {
    "accountNumber": "1027/2",
    "allowDelivery": false,
    "basePriceDelivery": 500,
    "canceled": false,
    "comments": "Test shipment for documentation",
    "companyId": null,
    "currency": "USD",
    "customPriceDelivery": false,
    "dateAllowDelivery": null,
    "dateCanceled": null,
    "dateDeducted": null,
    "dateInsert": "2026-10-06T11:30:44.000Z",
    "dateMarked": null,
    "dateResponsibleId": "2026-10-06T11:30:44.000Z",
    "deducted": false,
    "deliveryDocDate": null,
    "deliveryDocNum": null,
    "deliveryId": 1,
    "deliveryName": "Courier delivery",
    "deliveryXmlId": null,
    "discountPrice": 0,
    "empAllowDeliveryId": null,
    "empCanceledId": null,
    "empDeductedId": null,
    "empMarkedId": null,
    "empResponsibleId": 1317,
    "externalDelivery": false,
    "id": 1205,
    "id1c": null,
    "marked": false,
    "orderId": 1027,
    "priceDelivery": 500,
    "reasonMarked": null,
    "reasonUndoDeducted": null,
    "responsibleId": 1295,
    "shipmentItems": [],
    "statusId": "DN",
    "statusXmlId": null,
    "system": false,
    "trackingDescription": null,
    "trackingLastCheck": null,
    "trackingNumber": "VIBE-DOC-1",
    "trackingStatus": null,
    "updated1c": false,
    "version1c": null,
    "xmlId": "bx_6ac4cdd46e442"
  }
}
```

## Error response example

422 — no order with this `orderId` exists:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Unable to load the order",
    "b24Code": "0"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `MISSING_REQUIRED_FIELDS` | The required field `orderId` or `deliveryId` is missing or empty. The field name is in `message` |
| 400 | `READONLY_FIELD` | The body contains `deducted`. The response contains a `hint` with the [`ship`](./ship.md) and [`unship`](./unship.md) endpoints |
| 400 | `READONLY_FIELD` | The body contains another read-only field, such as `customPriceDelivery` or `accountNumber`. The field name is in `message` |
| 400 | `INVALID_PARAMS` | A field value does not match its type, such as a word in the numeric `deliveryId` or an object in the text `comments`. The field name is in `message` |
| 422 | `BITRIX_ERROR` | Bitrix24 rejected the creation. For example, no order with this `orderId` exists — `Unable to load the order` |
| 403 | `BITRIX_ACCESS_DENIED` | The key's user has no permission to edit orders in Bitrix24 |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode |
| 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 |

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

## See also

- [Shipments](/docs/entities/shipments)
- [Get a shipment](./get.md)
- [Update a shipment](./update.md)
- [Set the "shipped" mark](./ship.md)
- [Delete a shipment](./delete.md)
- [Shipment items](/docs/entities/shipment-items)
- [Orders](/docs/entities/orders)
- [Delivery services](/docs/entities/delivery-services)
