Get a public URL for Shopify webhooks#
Shopify can't deliver to localhost. An OtterKit webhook endpoint gives you a public HTTPS URL that answers Shopify around the clock and keeps every request, so nothing is lost while your laptop is closed or your handler is half written:
npx otterkit login
npx otterkit webhook --daemon --subdomain shopify-dev
# https://shopify-dev.otterkit.appThe name is reserved to your account, so the URL stays the same every time you start it. An endpoint costs $0.01 per hour while it is live and never more than $3 in any 30 days, and new accounts get 10 free credits. To look at a payload before you sign up, the try page gives you a live URL in the browser with no account.
Register the URL in Shopify#
- For an app, declare the subscription in
shopify.app.tomlor create it with the Admin API, with the topic (such asorders/create) and the endpoint URL. - For a single shop without an app, open the shop admin, go to Settings, then Notifications, then Webhooks, and create one there.
- Note the secret. App webhooks are signed with the app's client secret. Webhooks created in the shop admin are signed with the key shown on that Webhooks page.
Use https://shopify-dev.otterkit.app as the URL. Add a path if your handler expects one, such as https://shopify-dev.otterkit.app/hooks/shopify: the endpoint accepts any path and records it.
Verify the HMAC#
Shopify sends X-Shopify-Hmac-Sha256: the HMAC-SHA256 of the raw body, keyed with the secret and encoded as base64, not hex. Compute it over the raw bytes and compare in constant time.
X-Shopify-Topic names the event and X-Shopify-Shop-Domain says which shop sent it. X-Shopify-Webhook-Id identifies the delivery, so you can drop duplicates.
OtterKit can run the same check on every request as it arrives. Start the endpoint again with the secret, and each capture is marked valid, invalid or missing:
npx otterkit stop shopify-dev
npx otterkit webhook --daemon --subdomain shopify-dev --verify shopify:your-client-secretA failed check comes with its reason, such as signature_mismatch, so a wrong secret and a changed body look different. See signature verification for all 16 presets and the generic HMAC mode.
Send a test event#
Do the action in a development store, such as placing a test order, or run shopify app webhook trigger from the Shopify CLI. Webhooks made in the shop admin have a Send test notification link.
Then watch it land, or wait for it in a script:
# Follow requests as they arrive, with headers and bodies
npx otterkit inspect shopify-dev --follow
# Or block until the next POST, then print it as JSON
npx otterkit await shopify-dev --method POST --count 1 --timeout 120s --jsonYou can also skip Shopify entirely. otterkit send builds a sample event, signs it with your secret the way Shopify does and posts it straight to your local handler:
npx otterkit send shopify:orders/create 127.0.0.1:3000/hooks/shopify \
--secret your-client-secretReplay Shopify events into your local handler#
Once an event is captured you can send it to your handler as often as you like, with the original headers and body, without asking Shopify to fire it again:
# Send the latest captured event to a server on port 3000
npx otterkit replay shopify-dev --target 127.0.0.1:3000
# Or a specific one (1 is the oldest, -1 the latest)
npx otterkit replay shopify-dev --index 3 --target 127.0.0.1:3000Replays cost nothing and are added to the capture log with your handler's response next to them. If you would rather have events delivered live while you work, expose the handler with a tunnel instead and register the tunnel URL.
Retries, timeouts and duplicates#
- Shopify waits five seconds for a
2xx. It retries failures over the following hours and removes a subscription that keeps failing, so answer first and process afterwards. - Apps in the App Store must also handle the mandatory privacy webhooks and reject requests with a bad HMAC with a
401.
To see how your code copes when a delivery fails, the HTTP status codes guide has URLs that return any status on demand.
Questions about Shopify webhooks#
Which secret signs Shopify webhooks?#
For app subscriptions, the app's client secret from the Partner or Dev Dashboard. For webhooks created under Settings, Notifications, the key shown on that page.
Why does my HMAC never match?#
The two usual causes are comparing a hex digest with Shopify's base64 value, and hashing a parsed body instead of the raw bytes.
What happens if my handler takes longer than five seconds?#
Shopify counts it as failed and retries, so you may process the event twice. Queue the work and return 200 at once.