Merge Orders into One Shipment
Orders going to the same recipient, from the same source, can share one
Shipment that is bought with one Label. The Orders stay separate Orders, each
with its own orderId and status; what they share is the Shipment, its
parcel, its Rates, and its Label.
Every Order is created with exactly one Shipment. Merging is how several Orders end up in one box.
Orders can be merged only when every one of them:
- is
DraftorCreated, with no Label and no purchase running; - ships within the US;
- goes to the same address, with the same recipient name, email and phone wherever both Orders carry them;
- comes from the same source — for imported Orders, the same store — and the same Sub-account.
Find Orders that can be merged
GET/api/v1/orders/{orderId}/merge-candidates
Open find merge candidates in the API Reference.
Lists the Orders going to the same recipient and address as this one, from the
same source and Sub-account, that can share one Shipment with it — available
candidates first, then the newest. Orders that match but cannot be merged now
are listed too, with available: false and an unavailableReason:
AlreadyMerged, StatusNotMergeable, ActiveLabel, PurchaseInProgress,
ClosedAtStore, ScheduledDeliveries, MultipleShipments, LimitReached,
or UnreadableMetadata. At most 100 Orders to the same recipient are
considered, and they come back as one list: the operation is not paged. When the Order itself cannot start a merge — it ships abroad, its
address is incomplete, it is not Draft or Created, it has a Label, or a
purchase is running — candidates is empty. An Order already in a merged
Shipment is the exception to the status rule: the Shipment can take more Orders
whatever its Order's statuses, until a Label is bought for it or a purchase is
running.
For an Order that is already in a merged Shipment, currentShipmentId is that
Shipment and the candidates are the Orders that can be added to it.
Merge Orders
POST/api/v1/shipments/merge
Open merge orders in the API Reference.
Send 2 to 25 Orders in Draft or Created status. orderIds lists every
Order to merge, the anchor included; anchorOrderId is the Order that the merge
starts from, and its addresses are copied onto the merged Shipment.
{
"anchorOrderId": "5f2c1a10-2b3d-4e5f-8a9b-0c1d2e3f4a5b",
"orderIds": [
"5f2c1a10-2b3d-4e5f-8a9b-0c1d2e3f4a5b",
"114f6a6a-4b16-410a-9007-5086de668065"
]
}
parcel is optional. When it is omitted, the box has the anchor's size and
the Order's weights added together.
The response is the merged Shipment and its Orders, anchor first:
{
"success": true,
"data": {
"shipmentId": "b91a2c3d-4e5f-6a7b-8c9d-0e1f2a3b4c5d",
"orderIds": [
"5f2c1a10-2b3d-4e5f-8a9b-0c1d2e3f4a5b",
"114f6a6a-4b16-410a-9007-5086de668065"
]
},
"errors": null
}
Each Order's Shipment becomes the merged Shipment. Use the returned
shipmentId from here on.
Rate and buy the merged Shipment
Get Shipping Rates and
Buy a Label work on the merged shipmentId
exactly as on any other Shipment. The Label covers every Order in it: the
purchase response lists them in orderIds, anchor first, and orderId is the
anchor.
Rating or buying a merged Shipment is refused while another of its Orders is
cancelled, on hold, fulfilled or returned, or fails a pre-purchase check of its
own — closed at the store, shipped in scheduled deliveries, or still missing
details. The error keeps that refusal's own
code and names the Order in its metaData (orderId, orderNumber,
reason).
Change a merged Shipment
Each of these is allowed only while no Label covers the merged Shipment.
Add an Order
POST/api/v1/shipments/{shipmentId}/orders
Open add order to shipment in the API Reference.
Send { "orderId": "…" } to put one more Draft or Created Order into the
merged Shipment. The Order must go to the merged Shipment's own recipient
address. Its weight is added to the Shipment's parcel, and quoted Rates are
dropped. Adding an Order that is already in the Shipment answers with the
Shipment unchanged.
Change the address or parcel
PUT/api/v1/shipments/{shipmentId}
Open change merged shipment in the API Reference.
Send toAddress (US only), parcel, or both. They are the merged Shipment's
own: the Orders keep their own addresses and parcels. Quoted Rates are dropped.
Take it apart
POST/api/v1/shipments/{shipmentId}/unmerge
Open unmerge shipment in the API Reference.
Puts every Order back on the Shipment it had before, with its own address and
parcel, whatever the Orders' status, while no Label covers the Shipment and
none is being bought. The response lists each Order and the Shipment it is
back on. Taking apart a Shipment that was already taken apart answers with an
empty orders list.
Repeat a merge action safely
Merge, add, change and take apart each accept an optional Idempotency-Key
header of at most 200 characters, scoped to your account:
- While the key is retained, repeating the request with the same value returns the first answer instead of acting again, even if the Shipment changed since. Keys are retained for a limited period; once a key is no longer retained, the same value acts again on the Shipment as it is now.
- The same value with a different request, another merge action, or another
X-SubAccount-Idis refused with422 Idempotency.KeyReused. - A request that failed stores nothing and may be repeated with the same value.
Without the header the actions still converge: a repeated merge answers with the same Shipment, a repeated add changes nothing, and a repeated take-apart answers with an empty list. They do not always answer the same way as the first request, which is what the key is for.
Read merged Orders
List Orders is one row per Shipment. Orders merged into one Shipment are
listed once, as the anchor Order's row, with the other Orders nested in
mergedOrders in the same shape. They are not rows of their own, and
totalItemsCount and paging count rows, not Orders. Each row's shipmentId,
labelId and carrier are the shared Shipment's. mergedShipment carries
shipmentId, isAnchor and memberCount, and is null for an Order with a
Shipment of its own.
A merged Shipment is listed when the filter or search matches any of its Orders, so the row itself may not match a status filter — check the nested Orders too.
Get Order works for every Order in the Shipment. shipment is the shared
Shipment for each of them, shipment.isMerged is true, and
shipment.orderIds lists the Orders, anchor first.
Errors
| Status | When |
|---|---|
404 | An Order was not found, or the Shipment is not a merged Shipment of your account (Shipment.NotMerged) |
409 | Order.MergeRefused — metaData lists each refused Order with its reason: any candidate reason above, or DifferentRecipient, DifferentSubAccount, DifferentSource, or International |
409 | Shipment.MergeHasActiveLabel or Shipment.MergePurchaseInProgress — a Label covers the Shipment or is being bought |
409 | Shipment.MergeChangedConcurrently — the Orders changed meanwhile, or a request with the same Idempotency-Key is still being processed; send the request again |
422 | Invalid request — Order count, missing anchor, address or parcel, nothing to change — or Idempotency.KeyReused |
With X-SubAccount-Id, every Order and the Shipment must belong to that
Sub-account; a Shipment never mixes Sub-accounts.
What changed for existing integrations
Merging changes three things an integration built against earlier releases may rely on:
- List Orders is one row per Shipment. A merged Order other than the
anchor appears only nested in
mergedOrders, and paging counts rows. An integration that reads every Order from the top-level rows must also readmergedOrders. - An Order is created with exactly one Shipment.
shipmentsmust hold one entry on bothPOST /api/v1/ordersandPOST /api/v2/orders; more than one answers422 Validation.OneShipmentPerOrder, and an empty array is rejected as a missing Shipment. Create another Order for another box. - Responses carry new required fields. List Orders rows carry
origin,mergedShipmentandmergedOrders; Get Order carriesorigin, and itsshipmentcarriesdestination,isMergedandorderIds; a purchased Label carriesorderIds. A202Label purchase carrieserrorCodeanderrorMessage, and each carrier result in a Rates response carrieserrorField. A field the API Reference marks nullable may benull. Clients generated from the earlier contract may need regenerating.