Cancel an order
Description
Cancel an [order](https://shopify.dev/docs/api/admin-graphql/latest/objects/Order)
with full refund to the original payment method.
The mutation refunds the customer, sends a notification, restocks inventory,
and records a cancellation reason with staff notes. The response includes
[job details](https://shopify.dev/docs/api/admin-graphql/latest/objects/Job)
and comprehensive order status information.
Query
mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason, staffNote: $staffNote) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}
Variables
{
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refundMethod": {
"originalPaymentMethodsRefund": true
},
"restock": true,
"reason": "CUSTOMER",
"staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) { orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason, staffNote: $staffNote) { job { id done } orderCancelUserErrors { field message code } userErrors { field message } } }",
"variables": {
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refundMethod": {
"originalPaymentMethodsRefund": true
},
"restock": true,
"reason": "CUSTOMER",
"staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason, staffNote: $staffNote) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}`,
{
variables: {
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refundMethod": {
"originalPaymentMethodsRefund": true
},
"restock": true,
"reason": "CUSTOMER",
"staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."
},
},
);
const json = await response.json();
return json.data;
}
Ruby
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, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason, staffNote: $staffNote) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refundMethod": {
"originalPaymentMethodsRefund": 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)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason, staffNote: $staffNote) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}`,
"variables": {
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refundMethod": {
"originalPaymentMethodsRefund": true
},
"restock": true,
"reason": "CUSTOMER",
"staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!, $staffNote: String) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason, staffNote: $staffNote) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"orderId": "gid://shopify/Order/148977776",
"notifyCustomer": true,
"refundMethod": {
"originalPaymentMethodsRefund": true
},
"restock": true,
"reason": "CUSTOMER",
"staffNote": "Wrong size. Customer reached out saying they already re-purchased the correct size."
}'
Response
{
"orderCancel": {
"job": {
"id": "gid://shopify/Job/1fb9ff6d-d99c-49cf-80c5-6f915f0735ad",
"done": false
},
"orderCancelUserErrors": [],
"userErrors": []
}
}
Cancel an order and refund to store credit
Description
Cancel an [order](https://shopify.dev/docs/api/admin-graphql/latest/objects/Order)
and refund the payment to the customer's store credit account.
The mutation creates store credit with an expiration date and maintains the
refundable amount for future use. This example demonstrates the alternative refund
method for providing customer value without processing traditional refunds.
Query
mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}
Variables
{
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"storeCreditRefund": {
"expiresAt": "2026-06-19T23:35:01-04:00"
}
},
"restock": true,
"reason": "CUSTOMER"
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) { orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason) { job { id done } orderCancelUserErrors { field message code } userErrors { field message } } }",
"variables": {
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"storeCreditRefund": {
"expiresAt": "2026-06-19T23:35:01-04:00"
}
},
"restock": true,
"reason": "CUSTOMER"
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}`,
{
variables: {
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"storeCreditRefund": {
"expiresAt": "2026-06-19T23:35:01-04:00"
}
},
"restock": true,
"reason": "CUSTOMER"
},
},
);
const json = await response.json();
return json.data;
}
Ruby
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, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"storeCreditRefund": {
"expiresAt": "2026-06-19T23:35:01-04:00"
}
},
"restock": true,
"reason": "CUSTOMER"
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}`,
"variables": {
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"storeCreditRefund": {
"expiresAt": "2026-06-19T23:35:01-04:00"
}
},
"restock": true,
"reason": "CUSTOMER"
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation OrderCancel($orderId: ID!, $notifyCustomer: Boolean, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, notifyCustomer: $notifyCustomer, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"storeCreditRefund": {
"expiresAt": "2026-06-19T23:35:01-04:00"
}
},
"restock": true,
"reason": "CUSTOMER"
}'
Response
{
"orderCancel": {
"job": {
"id": "gid://shopify/Job/fce26225-36ae-4ae8-b42e-793a8c6bbdaa",
"done": false
},
"orderCancelUserErrors": [],
"userErrors": []
}
}
Cancel an order without refunding
Description
Cancel an [order](https://shopify.dev/docs/api/admin-graphql/latest/objects/Order)
without refunding the customer while still voiding authorized payments.
The mutation cancels the order and restocks inventory but maintains the refundable
amount, allowing for manual refund processing later. This example demonstrates order
cancellation without automatic customer refunds.
Query
mutation OrderCancel($orderId: ID!, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}
Variables
{
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"originalPaymentMethodsRefund": false
},
"restock": true,
"reason": "INVENTORY"
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2026-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation OrderCancel($orderId: ID!, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) { orderCancel(orderId: $orderId, refundMethod: $refundMethod, restock: $restock, reason: $reason) { job { id done } orderCancelUserErrors { field message code } userErrors { field message } } }",
"variables": {
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"originalPaymentMethodsRefund": false
},
"restock": true,
"reason": "INVENTORY"
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation OrderCancel($orderId: ID!, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}`,
{
variables: {
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"originalPaymentMethodsRefund": false
},
"restock": true,
"reason": "INVENTORY"
},
},
);
const json = await response.json();
return json.data;
}
Ruby
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!, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"originalPaymentMethodsRefund": false
},
"restock": true,
"reason": "INVENTORY"
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation OrderCancel($orderId: ID!, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}`,
"variables": {
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"originalPaymentMethodsRefund": false
},
"restock": true,
"reason": "INVENTORY"
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation OrderCancel($orderId: ID!, $refundMethod: OrderCancelRefundMethodInput!, $restock: Boolean!, $reason: OrderCancelReason!) {
orderCancel(orderId: $orderId, refundMethod: $refundMethod, restock: $restock, reason: $reason) {
job {
id
done
}
orderCancelUserErrors {
field
message
code
}
userErrors {
field
message
}
}
}' \
--variables \
'{
"orderId": "gid://shopify/Order/148977776",
"refundMethod": {
"originalPaymentMethodsRefund": false
},
"restock": true,
"reason": "INVENTORY"
}'
Response
{
"orderCancel": {
"job": {
"id": "gid://shopify/Job/90d193b2-6e66-49e9-b594-09abcbe48c1d",
"done": false
},
"orderCancelUserErrors": [],
"userErrors": []
}
}