Skip to content

Cancel Order

Cancels every cancellable item on an order. This is the same action as the Cancel button on the admin order-view screen, with the same eligibility gates as REST.

GraphQL returns a summary; REST returns the full detail

The GraphQL mutation returns a slim order summary (orderId, incrementId, status, statusLabel, grandTotal, success, message). The REST endpoint (POST /api/admin/orders/{id}/cancel) returns the full updated order-detail payload. Use REST, or re-query adminOrderDetail, when you need the complete order after cancelling.

Prerequisites

The example targets an order with cancellable items. Only orders that have not been invoiced or shipped can be canceled — once an order is invoiced (typically processing) it can only be refunded, and the mutation returns "This order has already been invoiced or shipped and can no longer be canceled. You can issue a refund instead." Pick an order in pending state (nothing invoiced yet) to cancel.

Operation

OperationTypePurpose
createAdminCancelOrderMutationCancel an order

Errors

Each failure returns the errors[] array with one of these messages:

ConditionLang keyMessage
Order is closedbagistoapi::app.admin.order.actions.cancel.closedClosed orders cannot be canceled.
Order is fraudbagistoapi::app.admin.order.actions.cancel.fraudFraud orders cannot be canceled.
Order has invoiced / shipped items (e.g. processing)bagistoapi::app.admin.order.actions.cancel.already-processedThis order has already been invoiced or shipped and can no longer be canceled. You can issue a refund instead.
No item has any quantity left to cancelbagistoapi::app.admin.order.actions.cancel.nothing-to-cancelThere is nothing to cancel on this order.
Admin role lacks sales.orders.cancelbagistoapi::app.admin.order.actions.cancel.no-permissionYou do not have permission to cancel orders.

Released under the MIT License.