$npx -y skills add 40RTY-ai/shopify-admin-skills --skill shopify-admin-shipping-cost-analysisRead-only: aggregates shipping revenue charged to customers vs. actual shipping line costs by carrier and method.
| 1 | ## Purpose |
| 2 | Compares the shipping amount charged to customers against the actual shipping cost recorded on orders, broken down by carrier and shipping method. Identifies where shipping is being subsidized (charged less than cost) or over-charged. Read-only — no mutations. |
| 3 | |
| 4 | ## Prerequisites |
| 5 | - Authenticated Shopify CLI session: `shopify store auth --store <domain> --scopes read_orders` |
| 6 | - API scopes: `read_orders` |
| 7 | - Actual shipping costs are only available if recorded via the Shopify Admin API or carrier-calculated shipping; manually entered orders may lack cost data. |
| 8 | |
| 9 | ## Parameters |
| 10 | |
| 11 | | Parameter | Type | Required | Default | Description | |
| 12 | |-----------|------|----------|---------|-------------| |
| 13 | | store | string | yes | — | Store domain (e.g., mystore.myshopify.com) | |
| 14 | | days_back | integer | no | 30 | Lookback window | |
| 15 | | format | string | no | human | Output format: `human` or `json` | |
| 16 | |
| 17 | ## Safety |
| 18 | |
| 19 | > ℹ️ Read-only skill — no mutations are executed. Safe to run at any time. |
| 20 | |
| 21 | ## Workflow Steps |
| 22 | |
| 23 | 1. **OPERATION:** `orders` — query |
| 24 | **Inputs:** `query: "financial_status:paid created_at:>='<NOW - days_back days>'"`, `first: 250`, select `shippingLines { title, discountedPriceSet, originalPriceSet, carrierIdentifier }`, pagination cursor |
| 25 | **Expected output:** Orders with shipping line details; paginate until `hasNextPage: false` |
| 26 | |
| 27 | 2. For each shipping line: record carrier (from `title` or `carrierIdentifier`), charged amount (`discountedPriceSet`), and actual cost if available |
| 28 | |
| 29 | 3. Group by carrier/method; calculate total charged, total cost, net subsidy/overage |
| 30 | |
| 31 | ## GraphQL Operations |
| 32 | |
| 33 | ```graphql |
| 34 | # orders:query — validated against api_version 2025-01 |
| 35 | query ShippingCostAnalysis($query: String!, $after: String) { |
| 36 | orders(first: 250, after: $after, query: $query) { |
| 37 | edges { |
| 38 | node { |
| 39 | id |
| 40 | name |
| 41 | createdAt |
| 42 | totalShippingPriceSet { |
| 43 | shopMoney { |
| 44 | amount |
| 45 | currencyCode |
| 46 | } |
| 47 | } |
| 48 | shippingLines(first: 5) { |
| 49 | edges { |
| 50 | node { |
| 51 | id |
| 52 | title |
| 53 | carrierIdentifier |
| 54 | originalPriceSet { |
| 55 | shopMoney { |
| 56 | amount |
| 57 | currencyCode |
| 58 | } |
| 59 | } |
| 60 | discountedPriceSet { |
| 61 | shopMoney { |
| 62 | amount |
| 63 | currencyCode |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | pageInfo { |
| 72 | hasNextPage |
| 73 | endCursor |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | ``` |
| 78 | |
| 79 | ## Session Tracking |
| 80 | |
| 81 | **Claude MUST emit the following output at each stage. This is mandatory.** |
| 82 | |
| 83 | **On start**, emit: |
| 84 | ``` |
| 85 | ╔══════════════════════════════════════════════╗ |
| 86 | ║ SKILL: Shipping Cost Analysis ║ |
| 87 | ║ Store: <store domain> ║ |
| 88 | ║ Started: <YYYY-MM-DD HH:MM UTC> ║ |
| 89 | ╚══════════════════════════════════════════════╝ |
| 90 | ``` |
| 91 | |
| 92 | **After each step**, emit: |
| 93 | ``` |
| 94 | [N/TOTAL] <QUERY|MUTATION> <OperationName> |
| 95 | → Params: <brief summary of key inputs> |
| 96 | → Result: <count or outcome> |
| 97 | ``` |
| 98 | |
| 99 | **On completion**, emit: |
| 100 | |
| 101 | For `format: human` (default): |
| 102 | ``` |
| 103 | ══════════════════════════════════════════════ |
| 104 | SHIPPING COST ANALYSIS (<days_back> days) |
| 105 | Orders analyzed: <n> |
| 106 | Total charged to customers: $<amount> |
| 107 | Free shipping orders: <n> |
| 108 | |
| 109 | By Carrier/Method: |
| 110 | "Standard Shipping" Orders: <n> Charged: $<n> Avg: $<n> |
| 111 | "Express" Orders: <n> Charged: $<n> Avg: $<n> |
| 112 | Output: shipping_cost_<date>.csv |
| 113 | ══════════════════════════════════════════════ |
| 114 | ``` |
| 115 | |
| 116 | For `format: json`, emit: |
| 117 | ```json |
| 118 | { |
| 119 | "skill": "shipping-cost-analysis", |
| 120 | "store": "<domain>", |
| 121 | "period_days": 30, |
| 122 | "orders_analyzed": 0, |
| 123 | "total_shipping_charged": 0, |
| 124 | "free_shipping_order_count": 0, |
| 125 | "currency": "USD", |
| 126 | "by_method": [], |
| 127 | "output_file": "shipping_cost_<date>.csv" |
| 128 | } |
| 129 | ``` |
| 130 | |
| 131 | ## Output Format |
| 132 | CSV file `shipping_cost_<YYYY-MM-DD>.csv` with columns: |
| 133 | `order_name`, `shipping_method`, `carrier`, `charged_amount`, `original_price`, `discount_applied`, `currency` |
| 134 | |
| 135 | ## Error Handling |
| 136 | | Error | Cause | Recovery | |
| 137 | |-------|-------|----------| |
| 138 | | `THROTTLED` | API rate limit exceeded | Wait 2 seconds, retry up to 3 times | |
| 139 | | No shipping lines | Digital products or free shipping store | Report $0 shipping revenue | |
| 140 | | Carrier identifier missing | Custom or manual shipping methods | Use `title` as carrier name | |
| 141 | |
| 142 | ## Best Practices |
| 143 | - Free shipping orders show $0 charged but the actual carrier cost is your subsidy — knowing this per carrier helps evaluate free shipping threshold decisions. |
| 144 | - `originalPriceSet` vs `discountedPriceSet` difference represent |