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. If your order has no items with qty_to_cancel > 0 (already canceled / fully shipped / closed / fraud) the mutation returns an errors[] entry like "There is nothing to cancel on this order." — pick an order in pending or processing state.

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.
No item has qty_to_cancel > 0bagistoapi::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.