Subscribing to webhooks
Your app must respond to mandatory webhook topics. In addition, your app can register optional webhook topics.
There are app-specific and shop-specific webhooks. We recommend app-specific webhooks for most apps, but there are reasons to register shop-specific webhooks. For more information, please read App-specific vs shop-specific webhooks.
Anchor to App-specific webhooks (recommended)App-specific webhooks (recommended)
The easiest way to configure webhooks is to use app-specific webhooks in shopify.app.toml. You can find more info in the webhooks documentation.
To set up a simple HTTPS webhook subscription, you can follow these steps:
- Add the topic to subscribe to in
shopify.app.toml. In this example we subscribe to theAPP_UNINSTALLEDtopic. - Review the required scopes for the webhook topics, and update your app scopes as necessary.
- Run
shopify app deployfrom the CLI to save your webhooks configuration.
Anchor to Shop-specific webhooksShop-specific webhooks
Shop-specific webhooks are useful when you need to subscribe to different webhook topics for different shops, or when a topic is not supported by app-specific webhooks.Configure shopifyApp and to setup shop-specific webhook subscriptions with the following steps:
- The webhooks you want to subscribe to. In this example we subscribe to the
APP_UNINSTALLEDtopic. - The code to register the
APP_UNINSTALLEDtopic after a merchant installs you app. HereshopifyAppprovides anafterAuthhook. - Review the required scopes for the webhook topics, and update your app scopes as necessary.
You can't register mandatory topics using this package, you must configure those in the Partner Dashboard instead.
Anchor to Set up your endpointsSet up your endpoints
Create a route in your app to handle incoming webhook requests for each callbackUrl you set in your configuration.Legitimate webhook requests are always POST requests signed by Shopify, so you must authenticate them before taking any action. To do this you must set up an action that uses the authenticate.webhook function to authenticate the request.
Please keep in mind that webhook endpoints should respond as quickly as possible. If you need to run a long-running job, then consider using background tasks.
Webhook endpoints must respond with an HTTP 200 code, or Shopify will retry.