$npx -y skills add 40RTY-ai/shopify-admin-skills --skill shopify-admin-cancel-and-restockCancel an unfulfilled order, optionally restock inventory, and optionally notify the customer — all in a single validated workflow.
| 1 | ## Purpose |
| 2 | Cancels an unfulfilled or partially-unfulfilled order with configurable restock, refund, and customer notification options — without navigating the Shopify admin. Useful for fraud exception handling, out-of-stock cancellations, or customer-requested cancellations before dispatch. Cannot cancel orders that are already fully fulfilled. |
| 3 | |
| 4 | ## Prerequisites |
| 5 | - Authenticated Shopify CLI session: `shopify auth login --store <domain>` |
| 6 | - API scopes: `read_orders`, `write_orders` |
| 7 | |
| 8 | ## Parameters |
| 9 | |
| 10 | | Parameter | Type | Required | Default | Description | |
| 11 | |-----------|------|----------|---------|-------------| |
| 12 | | store | string | yes | — | Store domain (e.g., mystore.myshopify.com) | |
| 13 | | format | string | no | human | Output format: `human` or `json` | |
| 14 | | dry_run | bool | no | false | Preview operations without executing mutations | |
| 15 | | order_id | string | yes | — | GID of the order (e.g., `gid://shopify/Order/12345`) | |
| 16 | | reason | string | no | `OTHER` | Cancel reason: `CUSTOMER`, `DECLINED`, `FRAUD`, `INVENTORY`, `STAFF`, `OTHER` | |
| 17 | | restock | bool | no | true | Restock inventory for cancelled line items | |
| 18 | | refund | bool | no | true | Issue refund for any captured payments | |
| 19 | | notify_customer | bool | no | true | Send cancellation email to customer | |
| 20 | | staff_note | string | no | — | Internal note recorded on the cancellation | |
| 21 | |
| 22 | ## Safety |
| 23 | |
| 24 | > ⚠️ Steps 2 executes `orderCancel` which is irreversible. A cancelled order cannot be reopened. If `refund: true`, any captured payment is automatically refunded. If `restock: true`, inventory quantities are immediately restored. Run with `dry_run: true` to verify the order state and confirm it is cancellable before committing. |
| 25 | |
| 26 | ## Workflow Steps |
| 27 | |
| 28 | 1. **OPERATION:** `order` — query |
| 29 | **Inputs:** `id: <order_id>` |
| 30 | **Expected output:** Order `name`, `displayFulfillmentStatus`, `displayFinancialStatus`, `cancelledAt` (must be null), `fulfillmentOrders.status` (must be `OPEN` or `ON_HOLD` — abort if any fulfillment order is `IN_PROGRESS` or `CLOSED`) |
| 31 | |
| 32 | 2. **OPERATION:** `orderCancel` — mutation |
| 33 | **Inputs:** `orderId`, `reason`, `restock`, `refund`, `notifyCustomer`, `staffNote` |
| 34 | **Expected output:** `orderCancelUserErrors` — empty on success; order is now cancelled with `cancelledAt` timestamp |
| 35 | |
| 36 | ## GraphQL Operations |
| 37 | |
| 38 | ```graphql |
| 39 | # order:query — validated against api_version 2025-01 |
| 40 | query OrderForCancel($id: ID!) { |
| 41 | order(id: $id) { |
| 42 | id |
| 43 | name |
| 44 | displayFulfillmentStatus |
| 45 | displayFinancialStatus |
| 46 | cancelledAt |
| 47 | totalPriceSet { |
| 48 | shopMoney { amount currencyCode } |
| 49 | } |
| 50 | lineItems(first: 50) { |
| 51 | edges { |
| 52 | node { |
| 53 | id |
| 54 | title |
| 55 | quantity |
| 56 | variant { |
| 57 | id |
| 58 | sku |
| 59 | inventoryQuantity |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | fulfillmentOrders(first: 5) { |
| 65 | edges { |
| 66 | node { |
| 67 | id |
| 68 | status |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | customer { |
| 73 | id |
| 74 | defaultEmailAddress { |
| 75 | emailAddress |
| 76 | } |
| 77 | firstName |
| 78 | lastName |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | ``` |
| 83 | |
| 84 | ```graphql |
| 85 | # orderCancel:mutation — validated against api_version 2025-01 |
| 86 | mutation OrderCancel( |
| 87 | $orderId: ID! |
| 88 | $reason: OrderCancelReason! |
| 89 | $restock: Boolean! |
| 90 | $refund: Boolean! |
| 91 | $notifyCustomer: Boolean! |
| 92 | $staffNote: String |
| 93 | ) { |
| 94 | orderCancel( |
| 95 | orderId: $orderId |
| 96 | reason: $reason |
| 97 | restock: $restock |
| 98 | refund: $refund |
| 99 | notifyCustomer: $notifyCustomer |
| 100 | staffNote: $staffNote |
| 101 | ) { |
| 102 | orderCancelUserErrors { |
| 103 | field |
| 104 | message |
| 105 | } |
| 106 | userErrors { |
| 107 | field |
| 108 | message |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | ``` |
| 113 | |
| 114 | ## Session Tracking |
| 115 | |
| 116 | **Claude MUST emit the following output at each stage. This is mandatory.** |
| 117 | |
| 118 | **On start**, emit: |
| 119 | ``` |
| 120 | ╔══════════════════════════════════════════════╗ |
| 121 | ║ SKILL: cancel-and-restock ║ |
| 122 | ║ Store: <store domain> ║ |
| 123 | ║ Started: <YYYY-MM-DD HH:MM UTC> ║ |
| 124 | ╚══════════════════════════════════════════════╝ |
| 125 | ``` |
| 126 | |
| 127 | **After each step**, emit: |
| 128 | ``` |
| 129 | [N/TOTAL] <QUERY|MUTATION> <OperationName> |
| 130 | → Params: <brief summary of key inputs> |
| 131 | → Result: <count or outcome> |
| 132 | ``` |
| 133 | |
| 134 | If `dry_run: true`, prefix every mutation step with `[DRY RUN]` and do not execute it. |
| 135 | |
| 136 | **On completion**, emit: |
| 137 | |
| 138 | For `format: human` (default): |
| 139 | ``` |
| 140 | ══════════════════════════════════════════════ |
| 141 | OUTCOME SUMMARY |
| 142 | Order: <name> |
| 143 | Cancellation reason: <reason> |
| 144 | Restocked: <true|false> |
| 145 | Refund issued: <true|false> |
| 146 | Customer notified: <true|false> |
| 147 | Errors: 0 |
| 148 | Output: none |
| 149 | ══════════════════════════════════════════════ |
| 150 | ``` |
| 151 | |
| 152 | For `form |