$npx -y skills add 40RTY-ai/shopify-admin-skills --skill shopify-admin-refund-and-reorderProcess a full or partial refund on an order and optionally create a replacement draft order for the customer.
| 1 | ## Purpose |
| 2 | Processes refunds and creates replacement orders without navigating the Shopify admin UI. This skill handles both the refund and the optional replacement draft order in a single workflow. |
| 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 | | refund_line_items | array | no | all refundable | Array of `{line_item_id, quantity}` to refund; if omitted, refunds all refundable quantities | |
| 17 | | reason | string | no | other | Refund reason: `customer`, `fraud`, `inventory`, `declined`, `other` | |
| 18 | | create_replacement | bool | no | false | If true, create a draft order with the same line items after refund | |
| 19 | | notify_customer | bool | no | true | Send refund notification email to customer | |
| 20 | |
| 21 | ## Safety |
| 22 | |
| 23 | > ⚠️ Steps 2 and 3 execute irreversible financial mutations. `refundCreate` cannot be undone — once a refund is processed, the payment cannot be re-captured. `draftOrderCreate` creates a new draft order that must be invoiced and paid separately. Run with `dry_run: true` to verify the refund line items and amounts before committing. Verify `refundableQuantity` per line item from Step 1 before proceeding. |
| 24 | |
| 25 | ## Workflow Steps |
| 26 | |
| 27 | 1. **OPERATION:** `order` — query |
| 28 | **Inputs:** `id: <order_id>` |
| 29 | **Expected output:** Full order with `displayFinancialStatus`, `lineItems` (with `refundableQuantity`), `transactions`, `customer`, `shippingAddress`; verify order is refundable before proceeding |
| 30 | |
| 31 | 2. **OPERATION:** `refundCreate` — mutation |
| 32 | **Inputs:** `input.orderId`, `input.refundLineItems` (from parameter or all refundable), `input.notify`, `input.note: <reason>` |
| 33 | **Expected output:** `refund.id`, `refund.totalRefundedSet`, `userErrors` |
| 34 | |
| 35 | 3. **OPERATION:** `draftOrderCreate` — mutation (only if `create_replacement: true`) |
| 36 | **Inputs:** `input.lineItems` (from original order line items), `input.customerId`, `input.shippingAddress`, `input.note: "Replacement for order <name>"` |
| 37 | **Expected output:** `draftOrder.id`, `draftOrder.name`, `draftOrder.invoiceUrl`, `userErrors` |
| 38 | |
| 39 | ## GraphQL Operations |
| 40 | |
| 41 | ```graphql |
| 42 | # order:query — validated against api_version 2025-01 |
| 43 | query OrderForRefund($id: ID!) { |
| 44 | order(id: $id) { |
| 45 | id |
| 46 | name |
| 47 | displayFinancialStatus |
| 48 | displayFulfillmentStatus |
| 49 | totalPriceSet { |
| 50 | shopMoney { amount currencyCode } |
| 51 | } |
| 52 | lineItems(first: 50) { |
| 53 | edges { |
| 54 | node { |
| 55 | id |
| 56 | title |
| 57 | quantity |
| 58 | refundableQuantity |
| 59 | variant { |
| 60 | id |
| 61 | sku |
| 62 | price |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | transactions(first: 10) { |
| 68 | id |
| 69 | kind |
| 70 | status |
| 71 | amountSet { |
| 72 | shopMoney { amount currencyCode } |
| 73 | } |
| 74 | gateway |
| 75 | } |
| 76 | refunds { |
| 77 | id |
| 78 | createdAt |
| 79 | totalRefundedSet { |
| 80 | shopMoney { amount currencyCode } |
| 81 | } |
| 82 | } |
| 83 | customer { |
| 84 | id |
| 85 | defaultEmailAddress { |
| 86 | emailAddress |
| 87 | } |
| 88 | firstName |
| 89 | lastName |
| 90 | } |
| 91 | shippingAddress { |
| 92 | address1 |
| 93 | city |
| 94 | province |
| 95 | country |
| 96 | zip |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | ``` |
| 101 | |
| 102 | ```graphql |
| 103 | # refundCreate:mutation — validated against api_version 2025-01 |
| 104 | mutation RefundCreate($input: RefundInput!) { |
| 105 | refundCreate(input: $input) { |
| 106 | refund { |
| 107 | id |
| 108 | createdAt |
| 109 | totalRefundedSet { |
| 110 | shopMoney { amount currencyCode } |
| 111 | } |
| 112 | } |
| 113 | userErrors { |
| 114 | field |
| 115 | message |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | ``` |
| 120 | |
| 121 | ```graphql |
| 122 | # draftOrderCreate:mutation — validated against api_version 2025-01 |
| 123 | mutation DraftOrderCreate($input: DraftOrderInput!) { |
| 124 | draftOrderCreate(input: $input) { |
| 125 | draftOrder { |
| 126 | id |
| 127 | name |
| 128 | invoiceUrl |
| 129 | } |
| 130 | userErrors { |
| 131 | field |
| 132 | message |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | ``` |
| 137 | |
| 138 | ## Session Tracking |
| 139 | |
| 140 | **Claude MUST emit the following output at each stage. This is mandatory.** |
| 141 | |
| 142 | **On start**, emit: |
| 143 | ``` |
| 144 | ╔══════════════════════════════════════════════╗ |
| 145 | ║ SKILL: refund-and-reorder ║ |
| 146 | ║ Store: <store domain> ║ |
| 147 | ║ Started: <YYYY-MM-DD HH:MM UTC> ║ |
| 148 | ╚══════════════════════════════════════════════╝ |
| 149 | ``` |
| 150 | |
| 151 | **After each step**, emit: |
| 152 | ``` |
| 153 | [N/TOTAL] <QUERY| |