# Loading units

Path: `/guide/loading-units`
Summary: Describe pallets, boxes, bags and mixed containers on a purchase order

A purchase order can describe not only *what* is expected (`items`) but *how it
physically arrives* — on pallets, in boxes, bags, bins, or mixed containers. These
physical units are **loading units**, sent in the `packagings` array of the
`POST /reception/bulk/purchase_orders` request body, alongside `items`.

## Create a purchase order with a loading unit

The simplest case: each SKU arrives in its own box, sitting directly at the location
(`packaging_level: 0`).

**Endpoint: Create a PO with loading units** — `POST /reception/bulk/purchase_orders` (operationId: bulkCreatePurchaseOrders)

| Field                               | Type | Required | Description                                                                      |
| ----------------------------------- | ---- | -------- | -------------------------------------------------------------------------------- |
| packagings                          |      |          | Array of physical units — see field reference below.                             |
| packagings\[].line_item_number    |      | yes      | Must match a line_item_number in items. Ties the unit to one order line (SKU). |
| packagings\[].barcode               |      | yes      | Identifier of the physical unit.                                                 |
| packagings\[].packaging_type       |      | yes      | One of bag, bin, box, pallet, mix_container.                                    |
| packagings\[].packaging_level      |      | yes      | Nesting depth. 0 = outermost unit, at the location.                              |
| packagings\[].quantity_in_package |      | yes      | Units of that line's SKU in this unit.                                           |

```json
{
"order_num": "PO-1LEVEL-001",
"delivery_date": "2024-03-13 12:50:00",
"third_party_id": 5393,
"warehouse_id": 1686,
"attributes": { "manually_created": true },
"items": [
  { "line_item_number": "00010", "product_id": 30816, "sku": "product_none_1_sku", "requested_quantity": 20 },
  { "line_item_number": "00020", "product_id": 30817, "sku": "product_none_2_sku", "requested_quantity": 40 }
],
"packagings": [
  { "line_item_number": "00010", "barcode": "BOX00010", "barcode_agency": "custom", "packaging_level": 0, "location_level_barcode": null, "quantity_in_package": 20, "packaging_type": "box", "dimensions_width": 30, "dimensions_height": 30, "dimensions_length": 30, "dimensions_weight": 30 },
  { "line_item_number": "00020", "barcode": "BOX00020", "barcode_agency": "custom", "packaging_level": 0, "location_level_barcode": null, "quantity_in_package": 40, "packaging_type": "box", "dimensions_width": 30, "dimensions_height": 30, "dimensions_length": 30, "dimensions_weight": 30 }
]
}
```

## The model

- Each entry in `packagings` is **one physical unit** (identified by `barcode`) that
  holds a quantity of exactly **one** order line's SKU — with the `mix_container`
  exception (see rule 4 below).
- `packaging_level` expresses **nesting depth**. **Level `0` is the outermost unit**,
  sitting directly at a warehouse location. Nesting goes *inward* with increasing
  levels: a box on a pallet is level `1`, a bag inside that box would be level `2`,
  and so on.
- `location_level_barcode` links a unit to its parent: it holds the `barcode` of the
  unit one level up (the same SKU's level `N-1` unit). It is `null` at level `0`.

## Field reference

| Field                                                          | Type           | Notes                                                                                                                                    |
| -------------------------------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `line_item_number`                                             | string         | **Required.** Must match a `line_item_number` in `items`. Ties the unit to one order line (SKU).                                         |
| `barcode`                                                      | string         | Identifier of the physical unit. Unique per unit — **except** a `mix_container`, which repeats the same `barcode` once per SKU it holds. |
| `barcode_agency`                                               | string \| null | Source of the barcode, e.g. `custom` for your own barcodes; `null` when not applicable.                                                  |
| `packaging_type`                                               | string (enum)  | One of `bag`, `bin`, `box`, `pallet`, `mix_container`.                                                                                   |
| `packaging_level`                                              | integer        | Nesting depth. `0` = outermost unit at the location; higher = nested inside.                                                             |
| `location_level_barcode`                                       | string \| null | `barcode` of the parent unit one level up (same SKU). `null` at level `0`.                                                               |
| `quantity_in_package`                                          | integer        | Units of that line's SKU contained in this unit. A parent's quantity equals the sum of its children.                                     |
| `dimensions_width` / `dimensions_height` / `dimensions_length` | number         | Dimensions of the unit.                                                                                                                  |
| `dimensions_weight`                                            | number         | Weight of the unit (note: named with the `dimensions_` prefix).                                                                          |

## Validation rules

1. **`line_item_number` is required on every packaging** and must exist in `items`. A
   `null` or unknown value is rejected with
   `line_item_numbers_not_found_in_any_purchase_items`.
2. **Levels are tracked per SKU and must be contiguous from `0`.** For a given
   `line_item_number`, if a unit exists at level `N`, units must also exist at every
   level `0 … N-1`, chained via `location_level_barcode`. A gap is rejected with
   `packaging_levels_must_be_contiguous`. In practice: every SKU must be rooted in its
   own level-`0` unit before it can be nested deeper.
3. **One SKU per `barcode` for every type except `mix_container`.** A `bag`, `bin`,
   `box`, or `pallet` row references a single `line_item_number`.
4. **A `mix_container` holds multiple SKUs** as several **level-`0` rows that share
   the same `barcode`**, one row per SKU (each with its own `line_item_number` and
   `quantity_in_package`). Because rule 2 requires each SKU to be rooted at level `0`,
   you **cannot** mix different SKUs by nesting them under a single parent belonging
   to another SKU — the mixed unit is expressed as repeated level-`0` rows instead.

## More examples

### Two levels — pallet → box, per SKU

Each SKU has a pallet (level `0`) with a box on it (level `1`). The box's
`location_level_barcode` points at its pallet's `barcode`.

**packagings**

```json
[
  {
    "line_item_number": "00010",
    "barcode": "PALLET0001",
    "barcode_agency": null,
    "packaging_level": 0,
    "location_level_barcode": null,
    "quantity_in_package": 20,
    "packaging_type": "pallet",
    "dimensions_width": 100,
    "dimensions_height": 100,
    "dimensions_length": 100,
    "dimensions_weight": 100
  },
  {
    "line_item_number": "00020",
    "barcode": "PALLET0002",
    "barcode_agency": null,
    "packaging_level": 0,
    "location_level_barcode": null,
    "quantity_in_package": 40,
    "packaging_type": "pallet",
    "dimensions_width": 100,
    "dimensions_height": 100,
    "dimensions_length": 100,
    "dimensions_weight": 100
  },
  {
    "line_item_number": "00010",
    "barcode": "BOX0001",
    "barcode_agency": "custom",
    "packaging_level": 1,
    "location_level_barcode": "PALLET0001",
    "quantity_in_package": 20,
    "packaging_type": "box",
    "dimensions_width": 30,
    "dimensions_height": 30,
    "dimensions_length": 30,
    "dimensions_weight": 30
  },
  {
    "line_item_number": "00020",
    "barcode": "BOX0002",
    "barcode_agency": "custom",
    "packaging_level": 1,
    "location_level_barcode": "PALLET0002",
    "quantity_in_package": 40,
    "packaging_type": "box",
    "dimensions_width": 30,
    "dimensions_height": 30,
    "dimensions_length": 30,
    "dimensions_weight": 30
  }
]
```

### One SKU split across several boxes on a pallet

A single SKU (60 units) on one pallet, split into three boxes of 20. The pallet's
`quantity_in_package` equals the sum of its boxes.

**packagings**

```json
[
  {
    "line_item_number": "00010",
    "barcode": "PALLET0001",
    "barcode_agency": null,
    "packaging_level": 0,
    "location_level_barcode": null,
    "quantity_in_package": 60,
    "packaging_type": "pallet"
  },
  {
    "line_item_number": "00010",
    "barcode": "BOX0001",
    "barcode_agency": "custom",
    "packaging_level": 1,
    "location_level_barcode": "PALLET0001",
    "quantity_in_package": 20,
    "packaging_type": "box"
  },
  {
    "line_item_number": "00010",
    "barcode": "BOX0002",
    "barcode_agency": "custom",
    "packaging_level": 1,
    "location_level_barcode": "PALLET0001",
    "quantity_in_package": 20,
    "packaging_type": "box"
  },
  {
    "line_item_number": "00010",
    "barcode": "BOX0003",
    "barcode_agency": "custom",
    "packaging_level": 1,
    "location_level_barcode": "PALLET0001",
    "quantity_in_package": 20,
    "packaging_type": "box"
  }
]
```

### Mixed container — multiple SKUs in one unit

One physical container holding three SKUs. It is a single `barcode` repeated once per
SKU, all at level `0`.

**packagings**

```json
[
  {
    "line_item_number": "00010",
    "barcode": "MIX0001",
    "barcode_agency": "custom",
    "packaging_level": 0,
    "location_level_barcode": null,
    "quantity_in_package": 15,
    "packaging_type": "mix_container",
    "dimensions_width": 120,
    "dimensions_height": 120,
    "dimensions_length": 120,
    "dimensions_weight": 120
  },
  {
    "line_item_number": "00020",
    "barcode": "MIX0001",
    "barcode_agency": "custom",
    "packaging_level": 0,
    "location_level_barcode": null,
    "quantity_in_package": 25,
    "packaging_type": "mix_container",
    "dimensions_width": 120,
    "dimensions_height": 120,
    "dimensions_length": 120,
    "dimensions_weight": 120
  },
  {
    "line_item_number": "00030",
    "barcode": "MIX0001",
    "barcode_agency": "custom",
    "packaging_level": 0,
    "location_level_barcode": null,
    "quantity_in_package": 10,
    "packaging_type": "mix_container",
    "dimensions_width": 120,
    "dimensions_height": 120,
    "dimensions_length": 120,
    "dimensions_weight": 120
  }
]
```

---

Website version: https://connect.pulpo.co/guide/loading-units
Whole guide in one file: https://connect.pulpo.co/llms-full.txt
Index of all pages: https://connect.pulpo.co/llms.txt
