//native
/**
* Submit Cancellation Request
* Ask the fulfillment service assigned to a fulfillment order to cancel it. Only valid for fulfillment orders assigned to an API fulfillment service whose request was accepted; the service then accepts or rejects it, after which Cancel Fulfillment Order closes it.
*/
export async function main(
auth: RT.Shopify,
fulfillment_order_id: string,
message: string | undefined
) {
const response = await fetch(
`https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
{
method: "POST",
headers: {
"X-Shopify-Access-Token": auth.token,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `mutation ($id: ID!, $message: String) { fulfillmentOrderSubmitCancellationRequest(id: $id, message: $message) { fulfillmentOrder { id status requestStatus } userErrors { field message } } }`,
variables: {
id: fulfillment_order_id.startsWith("gid://")
? fulfillment_order_id
: `gid://shopify/FulfillmentOrder/${fulfillment_order_id}`,
message: message || undefined,
},
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data, errors } = await response.json()
if (errors) {
throw new Error(JSON.stringify(errors))
}
if (data.fulfillmentOrderSubmitCancellationRequest.userErrors.length) {
throw new Error(
JSON.stringify(data.fulfillmentOrderSubmitCancellationRequest.userErrors)
)
}
return data.fulfillmentOrderSubmitCancellationRequest
}
Submitted by hugo989 3 hours ago