orderCancel
Requires access scope or
access scope. Also: This action cannot be reversed.
Cancels an order.
Arguments
- Anchor to notifyCustomernotify•
Customer BooleanDefault:false Whether to send a notification to the customer about the order cancellation.
- Anchor to orderIdorder•
Id ID!required The ID of the order to be canceled.
- Anchor to reasonreason•Order
Cancel requiredReason! The reason for canceling the order.
- Anchor to refundrefund•Boolean!required
Indicates whether to refund the amount paid by the customer. Authorized payments will be voided regardless of this setting.
- Anchor to restockrestock•Boolean!required
Whether to restock the inventory committed to the order. For unpaid orders fulfilled from locations that have been deactivated, inventory will not be restocked to the deactivated locations even if this argument is set to true.
- Anchor to staffNotestaff•
Note StringDefault:null A staff-facing note about the order cancellation. This is not visible to the customer.
Anchor to OrderCancelPayload returnsOrderCancelPayload returns
- •
The job that asynchronously cancels the order.
- Anchor to jobResultjob•
Result The job that asynchronously cancels the order.
- Anchor to orderCancelUserErrorsorder•
Cancel User Errors [OrderCancel non-nullUser Error!]! The list of errors that occurred from executing the mutation.
- Anchor to userErrorsuser•
Errors The list of errors that occurred from executing the mutation.
- Cancel an order
- orderCancel reference
Examples
mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refund: Boolean!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refund: $refund, restock: $restock, reason: $reason, staffNote: $staffNote) {
job {
id
done
}
jobResult {
id
done
}
orderCancelUserErrors {
field
message
code
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refund: Boolean!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) { orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refund: $refund, restock: $restock, reason: $reason, staffNote: $staffNote) { job { id done } jobResult { id done } orderCancelUserErrors { field message code } } }",
"variables": {
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refund": true,
"restock": true,
"reason": "CUSTOMER",
"staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refund: Boolean!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refund: $refund, restock: $restock, reason: $reason, staffNote: $staffNote) {
job {
id
done
}
jobResult {
id
done
}
orderCancelUserErrors {
field
message
code
}
}
}`,
{
variables: {
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refund": true,
"restock": true,
"reason": "CUSTOMER",
"staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refund: Boolean!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refund: $refund, restock: $restock, reason: $reason, staffNote: $staffNote) {
job {
id
done
}
jobResult {
id
done
}
orderCancelUserErrors {
field
message
code
}
}
}`,
"variables": {
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refund": true,
"restock": true,
"reason": "CUSTOMER",
"staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refund: Boolean!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refund: $refund, restock: $restock, reason: $reason, staffNote: $staffNote) {
job {
id
done
}
jobResult {
id
done
}
orderCancelUserErrors {
field
message
code
}
}
}
QUERY
variables = {
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refund": true,
"restock": true,
"reason": "CUSTOMER",
"staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."
}
response = client.query(query: query, variables: variables)