Skip to main content
Version: 1.0.0

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

ArgumentTypeRequiredDescription
commentStringYesThe reason for canceling the order. This will be recorded in the order history.
idIntNoThe unique identifier of the order to cancel. Either id or number must be provided.
numberStringNoThe 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:

FieldTypeDescription
successBooleanIndicates whether the order was successfully canceled.
order_numberStringThe 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 cancelGuestOrder mutation instead.
  • Either the id or number argument must be provided to identify the order.
  • If both id and number are 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.