> For the complete documentation index, see [llms.txt](https://developer.esw.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.esw.com/shopify/shopify-native/integration/order-and-item-level-cancellations.md).

# Order and Item-Level Cancellations

Sync cancellations between Shopify and ESW.

Use Shopify webhooks to capture changes.

Then apply the equivalent cancellation in the other system.

### Prerequisites

* You have an integration service that can receive Shopify webhooks.
* You can call:
  * Shopify Admin API (REST/GraphQL)
  * ESW order update / cancellation endpoints
* You’ve decided which system “owns” cancellations after order import.
  * Shopify-led cancellations (CS ops in Shopify)
  * ESW-led cancellations (warehouse / carrier constraints)

{% hint style="info" %}
Shopify and ESW can both emit retries or duplicate events.
{% endhint %}

### Webhook-driven cancellation flow

{% stepper %}
{% step %}

### Subscribe to Shopify cancellation signals

Use these topics depending on your operating model:

* `orders/cancelled` for full-order cancellations.
* `orders/updated` if you represent partial cancels as edits/adjustments.

#### Shopify docs <i class="fa-webhook" style="color:$primary;">:webhook:</i>:

* [orders/cancelled](https://shopify.dev/docs/api/admin-rest/2025-04/resources/webhook#event-topics-orders-cancelled)
* [orders/updated](https://shopify.dev/docs/api/admin-rest/2025-04/resources/webhook#event-topics-orders-updated)
  {% endstep %}

{% step %}

### Receive, validate, and enrich the event

When a webhook fires:

* Validate the Shopify HMAC signature.
* Deduplicate on webhook id / event id.
* Fetch the latest order state if needed for line-level details.
  {% endstep %}

{% step %}

### Decide what changed (full vs partial)

Normalize Shopify changes into one of these intents:

* **Full cancellation**: the entire order is cancelled.
* **Partial cancellation**: one or more items are cancelled/removed/adjusted.

Document your “partial cancel” representation.

Common patterns:

* ESW line-item cancel, Shopify uses refunds/adjustments.
* Shopify line-item edits, ESW uses item-level cancellation calls.
  {% endstep %}

{% step %}

### Apply Shopify-led cancellations to ESW

If Shopify is the source of truth:

* Map the Shopify order id to the ESW order reference.
* Send the cancellation intent to ESW:
  * Full order cancellation, or
  * Item-level cancellation with quantities and reasons (if supported)

Only cancel what ESW can still cancel.

Stop and alert if ESW has already shipped.
{% endstep %}

{% step %}

### Apply ESW-led cancellations to Shopify

If ESW can cancel post-import:

* Monitor ESW for cancellation events (order or line-item).
* Apply the corresponding update in Shopify using your chosen mechanism.

#### Shopify reference <i class="fa-code" style="color:$primary;">:code:</i> [orderCancel](https://shopify.dev/docs/api/admin-graphql/latest/mutations/orderCancel).

{% endstep %}

{% step %}

### Reconcile and monitor

Track and alert on:

* Cancellation write failures to either system
* Conflicts (already fulfilled, already refunded, already cancelled)
* Repeated retries / throttling

Add a daily reconciliation job for recent orders.
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developer.esw.com/shopify/shopify-native/integration/order-and-item-level-cancellations.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
