# Dispatches and invoicing

This guide shows you how to ship and invoice a sales order's dispatches
through the API. It explains what you can do with dispatches, how to move a
dispatch to a new status, what happens when it ships, and what to do when
Omono refuses a move or a ship fails.

In Omono, a sales order ships in one or more **dispatches**. A dispatch is
one shipment of some or all of the order's goods. Each dispatch moves
through a series of **workflow statuses** that your organisation sets up,
for example Awaiting Allocation, then Allocated, then Shipped. Moving a
dispatch to the last status, called the final status because its type is
`final`, ships the dispatch and **invoices** it.

## What you can do through the API

Your staff pick a dispatch's goods in Omono. Picking is when staff collect
a dispatch's goods and record which stock they took. The API can't pick a
dispatch, but it can:

- create a dispatch, with `POST /sales-orders/{id}/dispatches`. A new
  dispatch starts in the first status of your workflow with no stock
  allocated, so you can add dispatches to a draft order. An order that
  isn't a call-off can only be activated once all of its line items are on
  dispatches
- change a dispatch's date, courier, tracking number, serial numbers or
  line items, with `PATCH /sales-orders/{id}/dispatches/{dispatchId}`. You
  can change its line items' quantities only while it's in the first,
  unallocated stage of your workflow. If you move the date later, Omono
  emails the staff your organisation chose to tell about late dispatches
- delete a dispatch that's still in that first stage and has no picked
  goods, with `DELETE /sales-orders/{id}/dispatches/{dispatchId}`
- read an order's dispatches, with `GET /sales-orders/{id}/dispatches`, or
  with `include=dispatches` when you retrieve the order, and read one
  dispatch, with `GET /sales-orders/{id}/dispatches/{dispatchId}`
- move a dispatch to another status, including the final status that ships
  it, with `POST /sales-orders/{id}/transitions`
- mark a dispatch as paid for a proforma customer, who pays before the
  goods ship, with
  `POST /sales-orders/{id}/dispatches/{dispatchId}/proforma-paid`

Creating, changing and deleting a dispatch never changes stock levels. The
[Plan the dispatches for an order](/docs/recipes/plan-dispatches) recipe
shows these calls together.

## Move a dispatch to a new status

Your organisation names its own workflow statuses, but each status has a
type. Today there are four types: `unallocated`, `allocated`, `on_hold` and
`final`. Build your integration on the `type`, not on the status name, and
make sure your code copes with a type it doesn't recognise, because Omono
can add one.

1. Read the order with its dispatches, with
   `GET /sales-orders/{id}?include=dispatches`, and save the `ETag` header
   from the response. Each dispatch has a `legalTransitions` list, which
   holds the statuses it can move to right now. If a status's `blockedBy`
   list isn't empty, you can't use that status yet.

   ```json
   {
     "legalTransitions": [
       {
         "statusId": "…",
         "name": "Allocated",
         "type": "allocated",
         "blockedBy": []
       },
       {
         "statusId": "…",
         "name": "Shipped",
         "type": "final",
         "blockedBy": ["dispatch-not-fully-picked"]
       }
     ]
   }
   ```

2. Send `POST /sales-orders/{id}/transitions` with the `dispatchId` and the
   `statusId` you want. Send an `Idempotency-Key` too, and the sales order's
   `ETag` in `If-Match`, because a dispatch has no `ETag` of its own.

   ```http
   POST /api/v1/sales-orders/{id}/transitions
   Idempotency-Key: so-1042-allocate-1
   If-Match: "1758879330123"
   Content-Type: application/json

   {
     "dispatchId": "…",
     "statusId": "…"
   }
   ```

3. The `200` response returns `{ "applied": true, "salesOrder": … }`, and
   the order includes its dispatches, so you can see the new status without
   another request. If `applied` is `false`, the dispatch was already at
   that status and nothing changed.

Some moves change your stock. Moving a dispatch to a status whose type is
`allocated` reserves its stock. Omono reserves the full quantity even when
there isn't enough in stock, as it does in Omono itself: the stock item's
`allocated` can then be more than its `inStock`, and `insufficientStock`
shows it. Check stock first if you don't want that. Moving it back to a status whose type is
`unallocated` unpicks its goods and releases that stock. In Omono, staff
are asked to confirm this before the goods are unpicked, but a move through
the API doesn't ask for confirmation.

## Ship a dispatch

To ship a dispatch, move it to the final status, which is the status whose
type is `final`. You can send a few extra fields with this move:

```http
POST /api/v1/sales-orders/{id}/transitions
Idempotency-Key: ship-SO-1042-1
If-Match: "1758879330123"
Content-Type: application/json

{
  "dispatchId": "…",
  "statusId": "<the ID of the final status>",
  "invoiceDate": "2026-09-18",
  "courierId": "…",
  "trackingNo": "1Z999AA10123456784"
}
```

A move to the final status does all of the following:

- **It uses up an invoice number.** This can't be undone.
- **It sets the dates.** The dispatch gets its invoice date, due date and
  dispatch date. Both the invoice date and the dispatch date are set to the
  `invoiceDate` you send, which can be any day from 31 days ago up to
  today, in your organisation's time zone. If you leave it out, Omono uses
  today.
- **It releases unused stock.** Stock that was allocated to the dispatch
  but not used is released.
- **It sends your invoice email**, if that email is switched on in Omono.
  The email goes to the accounts email of the customer's accounts address,
  with copies to the people your email template names: the sales person,
  the account manager, the order contact and your own teams. If you send
  the invoice yourself, send `"suppressCustomerEmail": true`. This stops
  the email and its copies for this request only.
- **It saves the courier and tracking number**, if you send `courierId` and
  `trackingNo`. The invoice email and the invoice PDF print them. The
  courier must be one your organisation can use, as listed under
  [Purchasing and shipping](/docs#tag/purchasing-and-shipping).

Omono checks `invoiceDate` and `courierId` before it changes anything. A
date outside the allowed range fails with a `422` error and the code
`validation-failed`, and a courier you can't use fails with a `422` error
and the code `invalid-reference`. Neither uses up an invoice number.

## When a dispatch can't ship

Something in Omono can stop a dispatch from shipping. Read the order's
dispatches again right before you ship, because a change to a task or to the
customer doesn't change the order's `updated` time. A read with
`include=dispatches` always returns the whole order, even when you send
`If-None-Match`, so you always get the current list. If the final status,
which is the entry in `legalTransitions` whose type is `final`, has a
`blockedBy` list that isn't empty, each code in it names something that has
to be fixed first. These are today's codes:

| Code                        | What it means                                                                                                   | Who can fix it                                                                                                                                                                                                    |
| --------------------------- | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `dispatch-pick-not-saved`   | Picking is in progress in Omono, or it wasn't saved. In Omono the dispatch can look picked.                     | Your staff: they open the dispatch's picking in Omono, check it and press Save.                                                                                                                                   |
| `dispatch-not-fully-picked` | The goods aren't all picked in Omono yet.                                                                       | Your staff, in Omono.                                                                                                                                                                                             |
| `blocking-tasks`            | An open task that blocks shipping is linked to the order.                                                       | Your staff close the task in Omono. If your process allows it, a key with the `tasks:write` scope can also set the task's `blocksShipping` to `false`. A private task, which the API can't see, needs your staff. |
| `company-on-stop`           | The customer is on stop, which means staff have put a hold on the customer's account in Omono.                  | Your staff, in Omono.                                                                                                                                                                                             |
| `proforma-not-paid`         | The customer is a proforma customer, who pays before the goods ship, and the dispatch isn't marked as paid yet. | You, by marking the dispatch as paid with `/proforma-paid`, or your staff in Omono.                                                                                                                               |

Omono can add new codes to `blockedBy`, for example when it adds a new
rule about what can ship. So check whether the list is empty, rather than
looking for the codes above, and show any code you don't recognise to a
person. If you try to ship anyway, the request fails with a `409` error
whose code is the first one in the list, and whose `detail` names the
dispatch, such as SO-1042-2. The error names only that one, so read
`blockedBy` for the full list before you tell someone what to fix. To find a task that blocks shipping, list the tasks linked to the
order, which needs the `tasks:read` scope:

```http
GET /api/v1/tasks?linkedEntityType=sales_order&linkedEntityId=<order ID>
```

The API doesn't check the customer's credit limit when you ship. If your
organisation has turned on Omono's credit limit check for Xero, that check
runs only when staff ship a dispatch in Omono, and `blockedBy` never lists
it. If your process needs a credit check before goods leave, check the
customer's balance in your own system, or in Xero, before you ship through
the API.

## Other reasons a move fails

| Status | Code                        | What it means                                                                              | What to do                                                            |
| ------ | --------------------------- | ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------- |
| 409    | `order-not-active`          | The sales order's status is Draft or Cancelled. A cancelled order's dispatches can't move. | Activate a draft order first.                                         |
| 409    | `dispatch-order-mismatch`   | The dispatch belongs to a different sales order.                                           | Send the request to the order the dispatch is on.                     |
| 409    | `dispatch-shipped`          | The dispatch has already shipped, so its status can't change.                              | There's nothing to do. Read the order again to see its current state. |
| 409    | `dispatch-state-changed`    | Someone changed the dispatch at the same time, or is still shipping it.                    | Read the order again and decide again.                                |
| 422    | `invalid-transition-target` | The status doesn't exist in your organisation, or it's archived.                           | Take a `statusId` from `legalTransitions`.                            |
| 422    | `invalid-reference`         | The `dispatchId` isn't a dispatch in your organisation.                                    | Read the order again and take the dispatch's `id` from `dispatches`.  |

Omono checks the dispatch before the order's status. It checks that the
dispatch exists and belongs to the order in the path, then that the status
exists, and only then that the order is active. So a dispatch from another
order gets `dispatch-order-mismatch` even when the order in the path is a
draft. You're most likely to see `order-not-active` on an order that
someone cancelled in Omono, because the API can't cancel a sales order.

## Finish a ship that failed

Shipping does several things at once, so in rare cases it fails part-way
with a `500` error. If that happens, read the order again. A dispatch that
is shipped but has no `invoiceNo` hasn't been invoiced yet.

To finish it, send the same request again, with the same body and the same
`Idempotency-Key`, within 31 days of the failed ship. Omono completes the
invoicing and returns `"applied": true`. However many times you retry, the
dispatch gets only one invoice number. If the retry fails too,
[contact Omono](/docs/getting-started#getting-help) and quote the
`requestId`.

## Good to know

- **No credit check.** Today, Omono doesn't run your organisation's credit
  check when you ship through the API, because in Omono that check is only
  a prompt that staff see. If you need it, read the customer's balance
  yourself before you ship. If that changes, the changelog will say so, and
  a refused ship will have its own code.
- **Archived statuses.** You can send an archived status only when the
  dispatch is already at it. The response then has `"applied": false`.
- **When the invoice email isn't sent.** Omono doesn't send the invoice
  email when the customer's accounts address has no accounts email, when
  the sales person or the account manager has no email address, or when
  email sending is switched off for your organisation. Omono also holds
  the email back when your organisation has sent a very high number of
  emails that day. The ship still succeeds, and your staff can send the
  invoice from Omono.
