Cancel order items#
This guide walks through cancelling items of an order before shipment: cancelling the items, approving the cancellation, optionally crediting back fees and restocking, then finishing the process. The flow follows a repeating pattern — mutate, inspect order.actions to determine the next required step, and repeat until you call finishOrderItems.
Overview#
- Cancel items with
cancelOrderItems - Approve the cancellation with
approveOrderItems - (Optional) Credit back fees with
addContraFeesToOrderItems - (Optional) Restock items with
restockOrderItems - Finish the process with
finishOrderItems - (Optional) Notify the customer with
sendCancellationEmail
Understanding order actions#
After each mutation, the response includes order.actions. This array tells you which step to execute next and which item IDs are involved. Always check it before proceeding.
action value | Next step |
|---|---|
HANDLE_APPROVAL | Call approveOrderItems |
HANDLE_RESTOCK | Call restockOrderItems |
HANDLE_FINISH | Call finishOrderItems |
Understanding contra items#
When you cancel an item, you create a "contra" version of it. You generate a UUID v4 for contra_item_id yourself before calling the mutation (if you leave it empty one is generated for you, but then you won't know the ID). This ID is what you pass to subsequent steps (approve, restock, finish) instead of the original item_id.
Step 1 — Cancel the items#
Input: CancelOrderItemsInput!
| Name | Type | Required | Description |
|---|---|---|---|
order_id | String! | Required | ID of the order. |
items | [CancelOrderItemInput!]!▾ | Required | Items to cancel. |
Returns: Order
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID |
number | String! | Required | Order number |
total | Money! | Required | Total value |
currency | Currency! | Required | Currency code |
Generate one UUID per item before the request and store them locally — you will need the
contra_item_id values in every step that follows.
Step 2 — Approve the cancellation#
Pass the contra_item_ids from step 1 as items. The response includes the current fees on the order and the next required action.
Input: ApproveOrderItemsInput!
| Name | Type | Required | Description |
|---|---|---|---|
order_id | String! | Required | ID of the order. |
items | [String!]! | Required | The contra_item_id values from step 1. |
Returns: Order
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID |
number | String! | Required | Order number |
total | Money! | Required | Total value |
currency | Currency! | Required | Currency code |
Check order.actions in the response to determine which step comes next.
Step 2b — (Optional) Credit back fees#
If the order had fees (e.g. payment or shipping costs) that should be credited back to the customer, add contra entries for them. Only include fee IDs that are still present in the approveOrderItems response — the available fee IDs are returned under order.fees.
Input: AddContraFeesToOrderItemsInput!
| Name | Type | Required | Description |
|---|---|---|---|
item_ids | [String!]! | Required | The contra_item_id values from step 1. |
fees | [ContraFeeInput!]!▾ | Required | Fees to credit back. |
Returns: AddContraFeesToOrderItemsPayload
| Name | Type | Required | Description |
|---|---|---|---|
items | [CollectionItem!]!▾ | Required | Contra items the fees were attached to |
amount is in cents — 595 means € 5,95.Step 3 — (Optional) Restock items#
If order.actions contains HANDLE_RESTOCK, call this mutation to return the items to inventory. You can skip restocking by not calling this mutation — the items will not be added back to stock.
Input: RestockOrderItemsInput!
| Name | Type | Required | Description |
|---|---|---|---|
order_id | String! | Required | ID of the order. |
items | [RestockItemInput!]!▾ | Required | Items to restock. |
Returns: Order
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID |
number | String! | Required | Order number |
total | Money! | Required | Total value |
currency | Currency! | Required | Currency code |
After restocking, order.actions will contain HANDLE_FINISH.
Step 4 — Finish#
Completes the cancellation. The items are fully processed after this call.
Input: FinishOrderItemsInput!
| Name | Type | Required | Description |
|---|---|---|---|
order_id | String! | Required | ID of the order. |
items | [String!]! | Required | The contra_item_id values from step 1. |
Returns: Order
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID |
number | String! | Required | Order number |
total | Money! | Required | Total value |
currency | Currency! | Required | Currency code |
The cancellation is now complete.
Step 5 — (Optional) Send cancellation email#
Input: SendCancellationEmailInput!
| Name | Type | Required | Description |
|---|---|---|---|
order_id | String! | Required | ID of the order. |
item_ids | [String!]! | Required | The contra_item_id values from step 1. |
Returns: Order
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID |
number | String! | Required | Order number |
total | Money! | Required | Total value |
currency | Currency! | Required | Currency code |
The customer receives a cancellation confirmation for the processed items.
Notes#
finishOrderItemsmust always be the last call — it locks the processed items and closes the flow.- Steps marked (Optional) can be skipped; the flow will continue to
finishOrderItemswithout them. amountvalues in fee inputs are integers in cents — e.g.595means € 5,95.- The
order.actionsarray drives which steps are required. Its contents depend on the order's configuration (e.g. whether inventory tracking is enabled). Always read it rather than assuming a fixed sequence. reasonvalues are enums — see the fullCancelReasonvalue list in the schema reference.- To look up available inventory locations for restocking, query
inventoryLocations. - For processing a customer return after delivery, see Return order items.
- See Authentication for how to pass your API key.