anotherben/claude-harness/shopify-integration
Claude Code and agent skill by anotherben/claude-harness
- community
Checking that the SKILL.md file is still in the repository.
Shopify API and webhook integration guide. Use this skill before writing or modifying any Shopify webhook handler, API call, product sync, order sync, inventory push, or fulfillment code. Covers HMAC-SHA256 webhook verification, idempotency patterns, REST vs GraphQL API selection, cursor-based pagination, 429 rate limit handling, inventory sync pipeline, payment ledger dedup, fulfillment state machine, bundle expansion, and SKU override mapping. Invoke this when working on shopifyClient.js, shopifyWebhooks.js, shopifySync.js, or any file with "shopify" in the name — even for adding a simple webhook handler, because the verification and idempotency patterns must be exact.
Install
npx vskill@latest install anotherben/claude-harness/shopify-integrationSKILL.md
The same SKILL.md was published earlier as anotherben/claude-harness/shopify-integration.
Shopify Integration
This codebase has ~10,000+ lines of Shopify integration code across 20+ files. The patterns for webhook verification, API pagination, and sync dedup are precise — deviating from them causes silent data loss or duplicate processing.
TOP GOTCHAS (read these FIRST)
- `.trim()` the webhook secret —
SHOPIFY_WEBHOOK_SECRETfrom env vars often has trailing whitespace. Without.trim(), HMAC verification silently fails on every webhook. - Use `req.rawBody`, NOT `req.body` for HMAC verification —
req.bodyis parsed JSON (whitespace/key order changed). Must use the raw unparsed string. - Subsequent pages: ONLY `page_info` — REST cursor pagination breaks if you send filters alongside
page_infoon pages 2+. Shopify silently ignores the cursor and returns page 1 again. - Order webhooks do NOT include transactions — Must fetch via separate REST call
/orders/{id}/transactions.json. This is not in the webhook payload. - Don't add retry logic —
shopifyClient.jshas a built-in 429 interceptor (3 attempts, respectsretry-after). Adding your own compounds with it.
Before Writing Shopify Code
- Read `shopifyClient.js` (1,052 lines) — all API calls go through this client
- Read the existing handler for the webhook topic or sync type you're modifying
- Check the API version — currently
2025-10(set in shopifyClient constructor)
Webhook Verification (CRITICAL)
Every Shopify webhook MUST be verified with HMAC-SHA256 using the RAW request body:
Three critical details:
- Use
req.rawBody(the unparsed string), NOTreq.body(parsed JSON) — parsing changes whitespace and key order - Use
crypto.timingSafeEqual()for constant-time comparison — prevents timing attacks .trim()the webhook secret — trailing whitespace from env vars breaks HMAC
The raw body is preserved via Express verify callback in the body parser configuration.
Webhook Idempotency
Shopify retries webhooks that don't get a 200 response. Duplicate processing causes duplicate REX operations.
Always return 200 to Shopify even for duplicates — otherwise Shopify keeps retrying.
REST vs GraphQL: When to Use Each
| Operation | API | Why | |
|---|---|---|---|
| Single product CRUD | REST | Simpler, well-documented | |
| Bulk inventory adjustment | GraphQL inventorySetQuantities | Single call for multi-location | |
| Full product creation with variants | GraphQL productSet | Handles variants, pricing, metafields in one call | |
| Pagination over products/orders | REST with cursor | Link header pagination is reliable | |
| Sales channel publishing | GraphQL getPublications | REST doesn't expose this | |
| Customer CRUD | REST | Simpler, well-documented | |
| Order transactions | REST /orders/{id}/transactions.json | NOT included in order webhooks |
Key gotcha: Order webhook payloads do NOT include transaction details. You must fetch transactions separately via the REST API.
Pagination Patterns
REST API (Link Header Cursor)
Critical: On subsequent pages, send ONLY page_info — sending other params alongside it causes Shopify to ignore the cursor.
GraphQL (endCursor)
429 Rate Limit Handling
Built into shopifyClient.js via axios interceptor:
Don't add your own retry logic on top — it will compound with the built-in interceptor.
Inventory Sync Pipeline
Four-layer architecture (REX is source of truth):
- REX → Cortex: Background sync every 15 min →
inventorytable - Cortex → Shopify:
enqueuePush()→rex_sync_queue→ worker →POST /inventory_levels/set.json - Webhook Loop: Echo detection (90s window), override revert, circuit breaker (5 reverts/10min)
- Daily Reconciliation: 3:30 AM, max 200 corrections
Feature flags control each layer independently (see sync-worker skill).
Payment Ledger (Atomic Dedup)
For payment sync to REX, the ledger prevents duplicate financial operations:
On failure: the queue worker retries, but the ledger ensures only one successful sync.
Fulfillment State Machine
Fulfillment webhooks have a guard: only status === 'success' updates line items and triggers REX sync.
Non-success fulfillments (pending, cancelled, error) are recorded but do NOT update line items or trigger REX sync.
SKU matching: Match Shopify line_items by SKU to determine which items were fulfilled. Fallback to "fulfill all unfulfilled" only for legacy/reconciliation (no line_items available).
Bundle Expansion
Orders may contain Shopify bundles that need expansion to individual REX products:
- Primary metafield:
custom.bundle_products(Shopifylist.product_referencetype) - Legacy metafield:
bundly.bundle(Bundly app format) - Price distribution: Proportional (by individual price) or equal
- Config:
apps/api/src/config/shopifySync.js(74 lines)
Always check for bundle expansion before creating REX order items.
SKU Override System
For products that don't map 1:1 between Shopify and REX:
- Table:
shopify_sku_overrides - Actions:
SKIP(ignore line item) orMAP_TO_PRODUCT(remap to different product) - Use case: Service fees, gift wrapping, other non-inventory items
Lookup order: direct ID match → barcode match → SKU override → mark as problem.
API Chunking Limits
| Operation | Max per Request | Pagination | |
|---|---|---|---|
| Products REST | 250 | Link header cursor | |
| Customers REST | 250 | Link header cursor | |
| Inventory levels | 50 item IDs | Chunked loop | |
| GraphQL products | 100 | endCursor | |
| GraphQL mutations | 1 operation | N/A |
Common Mistakes
| Mistake | Why It Happens | Prevention | |
|---|---|---|---|
Using req.body for HMAC verification | Seems equivalent to rawBody | Must use req.rawBody — parsing changes the string | |
| Not returning 200 for duplicate webhooks | Want to signal "already processed" | Always return 200 — non-200 causes Shopify retries | |
| Adding retry logic around shopifyClient calls | Want resilience | Built-in 429 interceptor handles it — don't double-retry | |
Sending filters with page_info on subsequent pages | Copy-paste from first request | Subsequent pages: ONLY page_info parameter | |
| Fetching transactions from order webhook payload | Expects they're included | Must call /orders/{id}/transactions.json separately | |
| Not checking bundle expansion before REX sync | Bundles look like regular orders | Always check custom.bundle_products metafield | |
| Using REST for bulk inventory updates | REST works for single items | GraphQL inventorySetQuantities for multi-location | |
Assuming shopify_orders.rex_sync_status is accurate | Field exists on table | Known bug: all 34K dev orders show 'pending' — don't rely on this field |
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/shopify-integration/SKILL.md
Popularity
- Repository stars
- 7
- 7-day trend score
- 10
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/anotherben/claude-harness/shopify-integration)