Sync
Webhooks
There is a built method to listen for webhooks sent by Shopify back to your application. These are validated by verifying the HMAC signature Shopify sends on each request against a shared secret.
Webhooks registered through the Admin API — including those created by php artisan shopify:webhooks:register — are signed with your app's Client Secret, not the per-webhook secret shown in Settings > Notifications. Set SHOPIFY_WEBHOOK_SECRET to the same value as SHOPIFY_CLIENT_SECRET. The notification-panel secret only applies to webhooks you create manually in that panel.
Registering Webhooks
Via the Command Line (recommended)
The easiest way to register all webhooks is to run the built-in Artisan command. It will query your Shopify store, skip any that are already registered, and create any that are missing.
php artisan shopify:webhooks:register
In multi-store mode you can target a specific store:
php artisan shopify:webhooks:register --store=uk
If --store is omitted in multi-store mode, the command iterates all configured stores.
The command outputs a table showing the topic, callback URL, and whether each webhook was already registered, newly registered, or failed.
Removing old webhooks
Add --prune to also remove webhook subscriptions the addon no longer uses, for example after changing your site's domain:
php artisan shopify:webhooks:register --prune
It removes your app's subscriptions to the addon's webhook URLs (/!/shopify/webhook/...) that are:
for another URL, such as your old domain
for a topic the addon no longer handles
duplicates of one that's already registered
It lists them and asks before deleting anything; add --force to skip the question (for example in a deploy script). Subscriptions to other URLs, such as webhooks your own code registers through the same app, are left alone. Shopify only lists the subscriptions your app created, so webhooks created in Settings > Notifications or by other apps aren't affected.
If more than one site uses the same Shopify app (for example staging and production), each site's webhooks count as "another site" to the other. Check the list before confirming, and don't use --force there.
The command requires your Shopify credentials to be configured and your application's APP_URL to be set correctly, so that the callback URLs it generates are publicly accessible.
Via the Shopify Admin
You can also register webhooks manually:
Head to your Shopify admin
Click Settings > Notifications
Scroll down to Webhooks and click Create Webhook
Enter the URL as shown in the sections below.
Leave the type as
JSONand on the latest API.If this is your first webhook, you will be provided a secret which you should add to your .env as
SHOPIFY_WEBHOOK_SECRET. This panel secret only signs webhooks created here in the admin — if you also register webhooks via the Artisan command or Admin API, use your app's Client Secret instead (see the warning at the top of this page).
If you are trying to test any webhooks locally you'll need to use a service like Ngrok to forward your localhost to a secure endpoint.
Webhook Status
The Shopify Control Panel dashboard includes a Webhook Status card that queries your Shopify store and shows which webhooks are registered, whether their callback URLs match what the addon expects, and which topics are missing.
For any missing topics, run php artisan shopify:webhooks:register to create them automatically.
Webhook Endpoints
The following endpoints are registered by the addon. All webhook URLs follow the pattern:
https://YOURSITE/!/shopify/webhook/{resource}/{action}
Topic |
URL |
|---|---|
Collection Create |
|
Collection Update |
|
Collection Delete |
|
Product Create |
|
Product Update |
|
Product Delete |
|
Customer Create |
|
Customer Update |
|
Customer Delete |
|
Order Created |
|
Order Cancelled |
|
Refund Created |
|
Inventory Level Update |
|
Shopify will send the product update webhook on creation too, so a separate product/create webhook is optional for most setups.
The Order Created webhook scans all line_items and re-fetches the product data for each, adding the quantities to each product's and variant's purchase history (total_purchased, last_purchased).
Refund Created and Order Cancelled take quantities back off the purchase history, on the date of the refund or cancellation, and re-fetch the products to pick up any restocked inventory. Shopify records the items of a cancelled order as a refund too, so a cancellation only removes what its refunds don't already cover, and nothing is removed twice. Refunds of an amount only, without items, don't change the purchase history. Because quantities are removed in the month they're refunded, a month's figure can be negative; the yearly and lifetime totals are the net number sold.
The Inventory Level Update webhook updates a variant's stock when it changes in Shopify, for example after a stock adjustment, a transfer or a sale through another channel. It fetches the variant's total stock across locations and updates just that variant (inventory_quantity, inventory_policy) and its product's in_stock, without re-importing the whole product. In multi-store mode, where stock is kept per store or market, the product is re-imported for that store instead.
These use the read_orders and read_inventory scopes, which the addon already needs.
Multi-Store
In multi-store mode, the same webhook URLs are used for all stores. Configure a separate set of webhooks in each Shopify admin pointing to the same Statamic endpoints.
Shopify always sends an X-Shopify-Shop-Domain header with every webhook request. The addon uses this header to:
Identify which store the webhook came from (matched against each store's
urlin config).Verify the HMAC signature using that store's
webhook_secret.Pass the resolved store handle to any import jobs dispatched.
Webhook requests from domains not listed in multi_store.stores are rejected with a 403 response.
Each store's webhook secret must be set individually. See Env Values for the per-store env var pattern (SHOPIFY_STORE_{HANDLE}_WEBHOOK_SECRET). As above, when a store's webhooks are registered via the Admin API, this value is that store's Client Secret (SHOPIFY_STORE_{HANDLE}_CLIENT_SECRET).
Events
Each webhook listener also fires an event you can use to hook into with your own logic based on the payload received.
The available events are:
Thoughtco\Shopify\Events\CollectionCreate
Thoughtco\Shopify\Events\CollectionDelete
Thoughtco\Shopify\Events\CollectionUpdate
Thoughtco\Shopify\Events\CustomerCreate
Thoughtco\Shopify\Events\CustomerDelete
Thoughtco\Shopify\Events\CustomerUpdate
Thoughtco\Shopify\Events\ProductCreate
Thoughtco\Shopify\Events\ProductDelete
Thoughtco\Shopify\Events\ProductUpdate
Thoughtco\Shopify\Events\OrderCreate
Thoughtco\Shopify\Events\OrderCancelled
Thoughtco\Shopify\Events\RefundCreate
Thoughtco\Shopify\Events\InventoryLevelUpdate
Each event has one property $data with the payload data decoded to a stdClass.
For import job failures, see ProductImportFailed documented in Importing Data.