Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

shopify-webhooks

БесплатноБез исполняемых скриптовНе проверен

Register, verify, and reliably process Shopify webhook events for orders, inventory, and customers with HMAC validation and idempotency handling

finsilabsот finsilabs★ 69 звёзд на GitHub

Об этом скилле

Shopify Webhooks

Overview

Shopify webhooks deliver real-time event notifications to your app's HTTP endpoints when store events occur — orders placed, products updated, customers created, apps uninstalled. Every webhook payload includes an HMAC-SHA256 signature in the X-Shopify-Hmac-SHA256 header that must be verified before processing. Shopify guarantees at-least-once delivery, so handlers must be idempotent.

When to Use This Skill

  • When triggering fulfillment workflows the moment an order is paid
  • When syncing product or inventory changes to an external system in near real time
  • When sending customer data to a marketing automation platform upon registration
  • When cleaning up app data after a merchant uninstalls the app (app/uninstalled)
  • When implementing required GDPR webhooks for App Store compliance
  • When replacing polling loops that constantly query the Admin API for changes

Core Instructions

  1. Register webhooks via the Admin API

    Prefer registering webhooks programmatically in the afterAuth hook of your Shopify app. This ensures re-registration after reinstall:

    // Webhook registration helper
    export async function registerWebhooks(adminClient: GraphqlClient, appUrl: string) {
      const webhooksToRegister = [
        { topic: "ORDERS_CREATE", callbackUrl: `${appUrl}/webhooks/orders-create` },
        { topic: "ORDERS_UPDATED", callbackUrl: `${appUrl}/webhooks/orders-updated` },
        { topic: "PRODUCTS_UPDATE", callbackUrl: `${appUrl}/webhooks/products-update` },
        { topic: "APP_UNINSTALLED", callbackUrl: `${appUrl}/webhooks/app-uninstalled` },
        // Mandatory GDPR webhooks
        { topic: "CUSTOMERS_DATA_REQUEST", callbackUrl: `${appUrl}/webhooks/gdpr/customers-data-request` },
        { topic: "CUSTOMERS_REDACT", callbackUrl: `${appUrl}/webhooks/gdpr/customers-redact` },
        { topic: "SHOP_REDACT", callbackUrl: `${appUrl}/webhooks/gdpr/shop-redact` },
      ];
    
      for (const { topic, callbackUrl } of webhooksToRegister) {
        const response = await adminClient.request(`
          mutation WebhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: WebhookSubscriptionInput!) {
            webhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) {
              webhookSubscription { id topic }
              userErrors { field message }
            }
          }
        `, {
          variables: {
            topic,
            webhookSubscription: {
              callbackUrl,
              format: "JSON",
            },
          },
        });
    
        const { userErrors } = response.data.webhookSubscriptionCreate;
        if (userErrors.length > 0) {
          // ALREADY_EXISTS is expected on reinstall — not a real error
          const realErrors = userErrors.filter((e: any) => e.message !== "Address for this topic has already been taken");
          if (realErrors.length > 0) throw new Error(`Webhook registration failed: ${realErrors[0].message}`);
        }
      }
    }
    
  2. Verify the HMAC signature

    The most critical step — never process a webhook without verifying its signature:

    // middleware/verify-shopify-webhook.ts
    import crypto from "crypto";
    
    export function verifyShopifyWebhook(
      rawBody: Buffer,
      hmacHeader: string,
      secret: string
    ): boolean {
      const digest = crypto
        .createHmac("sha256", secret)
        .update(rawBody)
        .digest("base64");
    
      // Use timingSafeEqual to prevent timing attacks
      try {
        return crypto.timingSafeEqual(
          Buffer.from(digest),
          Buffer.from(hmacHeader)
        );
      } catch {
        return false;
      }
    }
    

    Express middleware example:

    // routes/webhooks.ts (Express)
    import express from "express";
    import { verifyShopifyWebhook } from "../middleware/verify-shopify-webhook";
    
    const router = express.Router();
    
    // CRITICAL: Use raw body parser BEFORE json parser for webhook routes
    router.use(
      "/webhooks",
      express.raw({ type: "application/json" }),
      (req, res, next) => {
        const hmac = req.headers["x-shopify-hmac-sha256"] as string;
        if (!verifyShopifyWebhook(req.body, hmac, process.env.SHOPIFY_API_SECRET!)) {
          return res.status(401).send("Unauthorized");
        }
        req.body = JSON.parse(req.body.toString());
        next();
      }
    );
    
  3. Handle webhook events with idempotency

    Shopify may deliver the same event multiple times. Use the X-Shopify-Webhook-Id header as an idempotency key:

    router.post("/webhooks/orders-create", async (req, res) => {
      // Respond 200 quickly — Shopify retries if response takes > 5 seconds
      res.status(200).json({ received: true });
    
      const webhookId = req.headers["x-shopify-webhook-id"] as string;
      const shop = req.headers["x-shopify-shop-domain"] as string;
      const order = req.body;
    
      // Idempote
    
Полный SKILL.md на GitHub

Установить shopify-webhooks в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

claude-code
cursor
gemini-cli
copilot
codex-cli
kiro
opencode

Вложенные файлы

evals/hmac-signature-verification-and-raw-body/criteria.jsonevals/hmac-signature-verification-and-raw-body/task.mdevals/idempotent-processing-with-background-qu/criteria.jsonevals/idempotent-processing-with-background-qu/task.mdevals/webhook-registration-with-gdpr-topics-an/criteria.jsonevals/webhook-registration-with-gdpr-topics-an/task.mdtile.json

FAQ

Что делает скилл shopify-webhooks?

Register, verify, and reliably process Shopify webhook events for orders, inventory, and customers with HMAC validation and idempotency handling

Как установить скилл shopify-webhooks?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл shopify-webhooks запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить shopify-webhooks с