# Errors & troubleshooting

Path: `/guide/errors`
Summary: Error shapes, common failures, and how to resolve them

When a call fails, PULPO tells you why in a consistent shape. This page covers that shape,
what each status code means, and the handful of mistakes that account for most rejected
requests.

## The error shape

Most errors return a JSON body with a human-readable `message`, an optional `code`, and —
for validation failures — a per-field `errors` map.

**Endpoint: Standard error shape** — `Error body`

```json
{
"message": "Validation failed",
"code": "VALIDATION_ERROR",
"errors": {
  "sku": ["has already been taken"]
}
}
```

Always read `errors` before `message` on a `400` — it names the exact field(s) at fault.

## Status codes

| Status | Meaning                                                 | Retry?  | What to do                                          |
| ------ | ------------------------------------------------------- | ------- | --------------------------------------------------- |
| `400`  | Bad request — invalid parameters or a failed validation | No      | Read `errors`, fix the field, resend                |
| `401`  | Invalid or expired token                                | No\*    | Re-authenticate, then retry once with the new token |
| `404`  | Resource not found                                      | No      | Check the id and that it belongs to your tenant     |
| `422`  | Semantic validation failed (e.g. picking a short line)  | No      | Inspect the structured body, fix the cause          |
| `429`  | Rate limit reached                                      | **Yes** | Wait `retry_after_seconds`, then back off           |
| `5xx`  | Server error                                            | **Yes** | Exponential backoff, capped attempts                |

> **NOTE: * 401 is a special case**
>
> A `401` isn't worth retrying with the *same* token — but a token expires after 60 minutes,
> so the correct recovery is to fetch a fresh token and retry the original request once.

## Insufficient stock (picking)

Creating picking tasks returns a **structured** error when a fulfillment order can't be
picked — `422` from `POST /picking/orders`, `400` from `POST /picking/bulk/orders`. The body
is a `PickingCreateError`: `errors[].items[].insufficient_stock` names the failing product,
and the bulk endpoint also returns `created[]` for the ones that succeeded.

**Endpoint: PickingCreateError** — `POST /picking/bulk/orders → 400`

```json
{
"created": [],
"errors": [
  {
    "id": 15411612,
    "order_num": "SO-2024-001",
    "fulfillment_sequence_number": "FO-0000145",
    "items": [
      {},
      {
        "id": "15411612",
        "order_num": "SO-2024-001",
        "insufficient_stock": "not enough stock available for item with product \"ABC-1\""
      }
    ]
  }
]
}
```

For turbo label picking the request itself succeeds (`204`). The same reason appears later
in the fulfillment order's `process_information.errors`.

## Common failures

> **WARNING: Merchant / channel mismatch (3PL)**
>
> The single most common cause of rejected records. On a **purchase order**, the merchant of
> the product and of the supplier must match the PO's merchant. On a **sales order**, the
> merchant + channel of the product, the customer, and the order must all agree. As a single
> merchant this can't happen — everything resolves to your one default pair.

> **WARNING: Reused order_num**
>
> `order_num` is unique. A repeat returns `has already been taken`. On a retry this means the
> order already exists — treat it as success. See [idempotency & retries](/guide/idempotency).

> **WARNING: Updates replace, they don't merge**
>
> `items` on a sales-order update **replaces the full line-item list** — send the complete set
> of lines, not just the ones you changed, or the omitted lines are dropped. The same replace
> semantics apply when closing packing boxes (the body is the complete boxes array). This is
> declarative, not a patch.

> **WARNING: Operating on a terminal state**
>
> State gates what you can do. Orders in `ended` or `cancelled` **cannot be updated**; an
> order in `ended` **cannot be cancelled**; an order in `picking` can't be cancelled when no
> packing locations are available. Check the [order states](/guide/order-states) before you
> mutate.

> **TIP: Empty list where you expected data?**
>
> A `200` with an empty collection usually means a **filter** excluded everything — most often
> a missing or wrong `warehouse_id`, or a `merchant_id` filter that doesn't match. Widen the
> filter and confirm the ids belong to your tenant.

## Debugging checklist

1. **Is the token fresh?** Tokens last 60 minutes — a stale one is a `401`, not a bug.
2. **Read `errors`, not just `message`.** The field-level map points straight at the cause.
3. **Right environment?** Staging ids don't exist in production. Confirm the base URL in the
   header selector matches where your data lives.
4. **Right `warehouse_id`?** Orders are warehouse-scoped; the wrong id returns empty or 404.
5. **Merchant + channel aligned?** For 3PL, re-check they match across product, party, order.
6. **Is the state terminal?** You can't mutate `ended` / `cancelled` orders.

---

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