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
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refund: Boolean!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {6 orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refund: $refund, restock: $restock, reason: $reason, staffNote: $staffNote) {7 job {8 id9 done10 }11 jobResult {12 id13 done14 }15 orderCancelUserErrors {16 field17 message18 code19 }20 }21 }`,22 {23 variables: {24 "orderId": "gid://shopify/Order/148977776",25 "notifyCustomer": true,26 "refund": true,27 "restock": true,28 "reason": "CUSTOMER",29 "staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."30 },31 },32);3334const data = await response.json();35
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)
Input variables
JSON1{2 "orderId": "gid://shopify/Order/148977776",3 "notifyCustomer": true,4 "refund": true,5 "restock": true,6 "reason": "CUSTOMER",7 "staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."8}
Response
JSON1{2 "orderCancel": {3 "job": {4 "id": "gid://shopify/Job/5f82274b-13ed-44f0-b8d8-6a448dfd1636",5 "done": false6 },7 "jobResult": {8 "id": "gid://shopify/OrderCancelJobResult/884324524",9 "done": false10 },11 "orderCancelUserErrors": []12 }13}