CancelCustomerOrderMutation
Description
Cancels a specific order for a logged-in customer. This mutation allows authenticated customers to cancel their orders by providing either the order ID or order number, along with a cancellation reason.
Endpoint
mutation cancelCustomerOrder($comment: String!, $id: Int, $number: String) {
cancelCustomerOrder(comment: $comment, id: $id, number: $number) {
# Return fields
}
}
Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
| comment | String | Yes | The reason for canceling the order. This will be recorded in the order history. |
| id | Int | No | The unique identifier of the order to cancel. Either id or number must be provided. |
| number | String | No | The order number (increment_id) of the order to cancel. Either id or number must be provided. |
Return Values
The mutation returns a PurchaseType object with the following fields:
| Field | Type | Description |
|---|---|---|
| success | Boolean | Indicates whether the order was successfully canceled. |
| order_number | String | The order number of the canceled order. |
Usage Example
mutation {
cancelCustomerOrder(
comment: "Changed my mind about this purchase",
number: "ORD-12345"
) {
success
order_number
}
}
Example Response
{
"data": {
"cancelCustomerOrder": {
"success": true,
"order_number": "ORD-12345"
}
}
}
Notes
- This mutation is specifically for authenticated customers. For guest users, use the
cancelGuestOrdermutation instead. - Either the
idornumberargument must be provided to identify the order. - If both
idandnumberare provided, the mutation will first attempt to find the order by ID, and if not found, it will try to find it by number. - If the order is already canceled, an error will be thrown with the message "The order was already canceled."
- If the order cannot be canceled for any reason, an error will be thrown with the message "The order could not be canceled."
- The comment provided will be recorded in the order history and may be visible to store administrators.
- The implementation includes a TODO comment about authenticating the user first, indicating that additional authentication checks may be added in the future.
- Depending on the store's configuration, canceling an order may trigger additional actions such as restoring inventory, refunding payments, or sending notification emails.