--- gid: AA46E2AA-5579-4A0A-A8B6-B9087A50AEE2 title: Subscribe to a webhook topic description: Learn how to set up and configure a webhook subscription using the app configuration file and GCP PubSub. --- Subscribe your app to Shopify webhook topics so that it will be alerted when an event occurs on a merchant store. Suppose you are building a warranty pricing app that determines which warranty options a customer can add to their cart, based on the cost of an order. When a customer is checking out, the total order cost is used to determine which warranty options a customer can select from. In this tutorial, you'll subscribe your app to a webhook topic to be alerted whenever a new order is created. ## What you'll learn In this tutorial, you'll learn how to do the following tasks: - Use your [app configuration file](/docs/apps/tools/cli/configuration#webhooks) to set up a webhook subscription. - Use cloud-based delivery methods like [Google Cloud's Pub/Sub event bus](https://cloud.google.com/pubsub) to receive webhooks. - Test your subscription is configured correctly and you are receiving webhooks. Shopify recommends using Google Pub/Sub as a cloud-based solution for delivering webhooks. You can also use [Amazon EventBridge](https://aws.amazon.com/eventbridge/). In instances where you want to hand-roll your own webhooks infrastructure, you may prefer your webhooks be delivered through [HTTPS](/docs/apps/webhooks/configuration/https). During development, you may choose to use your app's URL or external mock server sites like [webhook.site](https://webhook.site/) and [Beeceptor](https://beeceptor.com/). These are not recommended for production. You must use [Shopify CLI **version 3.63.0** or higher](https://www.npmjs.com/package/@shopify/cli) to configure app-specific webhook subscriptions. Scaffold an app that uses the [Remix template](https://github.com/Shopify/shopify-app-template-remix). Set up your Google Cloud account to use Pub/Sub. Sign up for Amazon EventBridge. For development, you can use mock servers like [Hookdeck Console](https://console.hookdeck.com/) or [webhook.site](https://webhook.site/) can be used for development. {/* STEP 1: SET UP YOUR APP TO RECEIVE WEBHOOKS DEPENDING ON THE DELIVERY METHOD */} {/* STEP 1.1: PUBSUB */} ## Set your app up to receive webhooks from Google Pub/Sub To receive webhooks via a cloud-based event bus like Pub/Sub from Google Cloud, you must first set up a connection between your app and Pub/Sub. ### Set up a connection between Google Pub/Sub and Shopify 1. In the Partner Dashboard, navigate to **Apps**. 1. Click on the name of your app. 1. Click on **Configuration**. 1. From the **[Google Pub/Sub console](https://cloud.google.com/pubsub)**, copy the Shopify service account address. ### Grant Shopify access to publish webhooks to your Google Pub/Sub topic 1. Click on **Topics** in the left panel. 1. Click on the **Create a topic** button. Enter in a name, keep the remaining defaults and click on **Create**. 1. Next to the Google Pub/Sub topic you just created, click `⋮` and then click **View permissions**. 1. Click on **ADD PRINCIPAL**. 1. Paste the Shopify service account address (the one you used to configure the URI in the TOML file) into the **New principals** text box. 1. In the **Role** drop-down list, select **Pub/Sub** as the type, and specify the role as **Pub/Sub Publisher**. 1. Click **Save**. {/* STEP 1.2: EVENTBRIDGE */} ## Set your app up to receive webhooks from Amazon EventBridge ### Set up a connection between Amazon EventBridge and Shopify 1. Under **Amazon EventBridge**, click **Create source**. 1. Paste your AWS account ID, and choose your AWS region. You need the AWS region when you [associate an event bus](#step-2-associate-an-event-bus) with the source. 1. Provide a unique event source name. Each event source requires a unique name. If you have multiple apps, then consider a name that matches your app. 1. Click **Create**. ### Grant Shopify access to publish webhooks to your Amazon EventBridge event bus 1. In the AWS console, under **EventBridge**, navigate to the [Partner event sources](https://console.aws.amazon.com/events/home#/partners) page. 1. In the **Region** drop-down list, select the AWS region that you chose when you set up your event source. These regions must match for the event bus to connect with the event source. 1. Click the event source [that you created](#step-1-set-up-an-event-source), and note the ARN found under **Partner event source ARN**. You need this address to [subscribe to a webhook](#step-4-subscribe-to-a-webhook). 1. Click **Associate with event bus**. 1. On the next page, click **Associate**. ### Create a rule to ensure the webhook is routed to the target you want it sent to A rule is Amazon Eventbridge’s way of ensuring the event is routed to the target you want it sent to Amazon EventBridge groups and sorts the events that your event source sends based on the rules that you define. After you set up your event source and associate it with an event bus, create a rule that tells AWS what to do with events it receives on the bus. To define multiple rules, repeat this step for each rule. > Note: > As your app audience grows, your traffic can increase significantly. Consider using [AWS CloudWatch](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-monitoring-cloudwatch-metrics.html) to monitor your EventBridge integration for usage patterns and errors. For example, you can [trigger an alert](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-troubleshooting.html#create-alarm-broken-event-rules) if an EventBridge rule is broken. 1. In the AWS console navigation menu, click [Rules](https://console.aws.amazon.com/events/home#/events). 1. In the drop-down list, select your event bus. 1. Click **Create rule**. 1. Provide a rule name. 1. Provide a description for the rule. 1. In the **Define pattern** section, choose **Event pattern**, and select **Pre-defined pattern by service**. You can also [define a custom event pattern](#define-a-custom-event-pattern) for your rule. 1. In the list of providers, choose **All Events**. 1. In the **Service name** drop-down list, select **Shopify**. This makes sure that only events that Shopify sends are processed by this rule. 1. In the **Select event bus** section, select the event bus that will use this rule. 1. In the **Select targets** section, choose a Lambda function or SQS queue. Events processed by this rule will be sent to the function or queue that you select. 1. Click **Create**. ### Optional: Define a custom event pattern When you create a rule, you can process events separately depending on factors like which shop generated the event or which resource triggered the event. [Event patterns](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html) in EventBridge rules have the same structure as the payloads that they match. Matching values are added to an array and compared using `OR`. You can also match by prefix using the **prefix** key. 1. In the **Define pattern** section, select **Event pattern**. 1. Select **Custom pattern**. 1. Provide a custom pattern that matches [the structure of an Amazon EventBridge payload](#eventbridge-payload-structure). 1. Click **Save**. {/* STEP 1.3: HTTPS */} ## Set your app up to receive webhooks using HTTPS delivery If you choose to use HTTPS delivery for your webhooks system, it will require additional steps to be production-ready. You can learn more about these [key considerations here](/docs/apps/build/webhooks/subscribe/https). {/* STEP 2: CONFIGURE YOUR WEBHOOK SUBSCRIPTION */} {/* STEP 2.1: PUBSUB */} ## Configure your webhook subscription ### Update your access scopes Some webhook topics require scopes in order to be used. Since we want to know about when an order has been created, we need to include the `read_orders` scope in the configuration file. * To determine which scopes are required for each topic, use the [Webhooks reference](/docs/api/webhooks). * The complete list of Shopify API access and approval scopes are listed [here](https://shopify.dev/docs/api/usage/access-scopes). Scopes that access private customer data require to take manual steps in your Partner Dashboard. This is true of `read_orders`. Navigate to your app > `API Access` > Access requests > Protected customer data access and fill out only the first step, then save. Reinstall your app in the admin to ensure the granted scope on your app is registered with Shopify. ### Select the API version The API version impacts which topics are available to subscribe to. The Remix template defaults to the latest version in your app configuration file. However, you can [update the API version](https://shopify.dev/docs/apps/webhooks/versioning) as needed. ### Add topics to subscribe to To determine which topic to subscribe to, use the [Webhooks reference](/docs/api/webhooks). In this example, your topic name will be in a list and formatted as: `topics = ["orders/create"]`. ### Configure the endpoint where you will receive webhooks Your endpoint address should follow the following format: ``` pubsub://{project-id}:{topic-id} ``` {/* STEP 2.2: EVENTBRIDGE */} ## Configure your webhook subscription ### Update your access scopes Some webhook topics require scopes in order to be used. Since we want to know about when a product has been updated, we need to include the `read_products` scope in the configuration file. * To determine which scopes are required for each topic, use the [Webhooks reference](/docs/api/webhooks). * The complete list of Shopify API access and approval scopes are listed [here](https://shopify.dev/docs/api/usage/access-scopes). Scopes that access private customer data require to take manual steps in your Partner Dashboard. This is true of `read_orders`. Navigate to your app > `API Access` > Access requests > Protected customer data access and fill out only the first step, then save. Reinstall your app in the admin to ensure the granted scope on your app is registered with Shopify. ### Select the API version The API version impacts which topics are available to subscribe to. The Remix template defaults to the latest version in your app configuration file. However, you can [update the API version](docs/apps/build/webhooks/use-newer-api-version) as needed. ### Add topics to subscribe to To determine which topic to subscribe to, use the [Webhooks reference](/docs/api/webhooks). In this example, your topic name will be in a list and formatted as: `topics = ["orders/create"]`. ### Configure the endpoint where you will receive webhooks Your endpoint address should be your ARN. You can find details in your Amazon EventBridge console: **Partner Event Sources** > **Select your event source** > **Partner event source ARN**. {/* STEP 2.3: HTTPS */} ## Configure your webhook subscription ### Update your access scopes Some webhook topics require scopes in order to be used. Since we want to know about when a product has been updated, we need to include the `read_products` scope in the configuration file. * To determine which scopes are required for each topic, use the [Webhooks reference](/docs/api/webhooks). * The complete list of Shopify API access and approval scopes are listed [here](https://shopify.dev/docs/api/usage/access-scopes). Scopes that access private customer data require to take manual steps in your Partner Dashboard. This is true of `read_orders`. Navigate to your app > `API Access` > Access requests > Protected customer data access and fill out only the first step, then save. Reinstall your app in the admin to ensure the granted scope on your app is registered with Shopify. ### Select the API version The API version impacts which topics are available to subscribe to. The Remix template defaults to the latest version in your app configuration file. However, you can [update the API version](docs/apps/build/webhooks/use-newer-api-version) as needed. ### Add topics to subscribe to To determine which topic to subscribe to, use the [Webhooks reference](/docs/api/webhooks). In this example, your topic name will be in a list and formatted as: `topics = ["orders/create"]`. ### Configure the endpoint where you will receive webhooks Your endpoint should utilize your HTTPS URL. Shopify recommends using the relative URL `"/webhooks"` if you are using your app URL as your HTTPS delivery endpoint. This is because your app URL will update every time you run `shopify app deploy`. Regardless of the endpoint you choose to use, it must include `https://` otherwise it will fail validation. {/* STEP 3: PROCESS YOUR WEBHOOKS */} {/* STEP 3.1: PUBSUB */} ## Process your webhooks Update your `webhooks` file in your app routes (`apps/routes`) to process the event data once your app has received a webhook. In this case, we will just print to the console. Notice the current implementation of Shopify's Remix template requires you to style your webhook topic using screaming case (e.g. `ORDERS_CREATE`). This is the GraphQL ENUMS syntax. You can see the full list of topic enums in the [Webhooks reference](/docs/api/webhooks). {/* STEP 3.2: EVENTBRIDGE */} ## Process your webhooks Update your `webhooks` file in your app routes (`apps/routes`) to process the event data once your app has received a webhook. In this case, we will just print to the console. Notice the current implementation of Shopify's Remix template requires you to style your webhook topic using screaming case (e.g. `ORDERS_CREATE`). This is the GraphQL ENUMS syntax. You can see the full list of topic enums in the [Webhooks reference](/docs/api/webhooks). {/* STEP 3.3: HTTPS */} ## Process your webhooks Update your `webhooks` file in your app routes (`apps/routes`) to process the event data once your app has received a webhook. In this case, we will just print to the console. Notice the current implementation of Shopify's Remix template requires you to style your webhook topic using screaming case (e.g. `ORDERS_CREATE`). This is the GraphQL ENUMS syntax. You can see the full list of topic enums in the [Webhooks reference](/docs/api/webhooks). {/* STEP 4: CONFIRM YOUR SUBSCRIPTION HAS BEEN CREATED */} {/* STEP 4.1: PUBSUB */} ### Confirm the subscription has been added to this version of your app While working in development mode, however, the subscription is created once you have deployed your app, due to hot reloading. 1. Save your TOML file. 1. To deploy your app, run [`shopify app deploy`](/docs/api/shopify-cli/app/app-deploy). 1. Navigate to the Partner Dashboard, click on your app, then **Versions** to see the latest version of your app. On this page, you will see `orders/create` listed in the **Webhooks** section. Subscriptions are live on a store as soon as the app is installed, and assuming you have deployed. This step abstracts away calls to the [`pubSubWebhookSubscriptionCreate`](/docs/api/admin-graphql/latest/mutations/pubSubWebhookSubscriptionCreate) GraphQL mutation. To learn more about subscribing to webhook topics using the Admin API, see the Subscribe using Admin API guide. {/* STEP 4.2: EVENTBRIDGE */} ### Confirm the subscription has been added to this version of your app While working in development mode, however, the subscription is created once you have deployed your app, due to hot reloading. 1. Save your TOML file. 1. To deploy your app, run [`shopify app deploy`](/docs/api/shopify-cli/app/app-deploy). 1. Navigate to the Partner Dashboard, click on your app, then **Versions** to see the latest version of your app. On this page, you will see `orders/create` listed in the **Webhooks** section. Subscriptions are live on a store as soon as the app is installed, and assuming you have deployed. This step abstracts away calls to the [`pubSubWebhookSubscriptionCreate`](/docs/api/admin-graphql/latest/mutations/pubSubWebhookSubscriptionCreate) GraphQL mutation. To learn more about subscribing to webhook topics using the Admin API, see the Subscribe using Admin API guide. {/* STEP 4.3: HTTPS */} ### Confirm the subscription has been added to this version of your app While working in development mode, however, the subscription is created once you have deployed your app, due to hot reloading. 1. Save your TOML file. 1. To deploy your app, run [`shopify app deploy`](/docs/api/shopify-cli/app/app-deploy). 1. Navigate to the Partner Dashboard, click on your app, then **Versions** to see the latest version of your app. On this page, you will see `orders/create` listed in the **Webhooks** section. Subscriptions are live on a store as soon as the app is installed, and assuming you have deployed. This step abstracts away calls to the [`pubSubWebhookSubscriptionCreate`](/docs/api/admin-graphql/latest/mutations/pubSubWebhookSubscriptionCreate) GraphQL mutation. To learn more about subscribing to webhook topics using the Admin API, see the Subscribe using Admin API guide. {/* STEP 5: TEST YOUR SUBSCRIPTION */} {/* STEP 5.1: PUBSUB */} ## Test your subscription ### Manually trigger an event in your test shop Most webhook topics will fire immediately if you trigger the corresponding event your dev store. 1. Navigate to your test shop and create a new order. 1. The webhook payload should print to your Google Pub/Sub console. A small number of webhook topics will not fire immediately if you trigger an event in your test shop. They include: - The [customers/redact topic](/docs/apps/build/privacy-law-compliance#customers-redact) - The [shop/redact topic](/docs/apps/build/privacy-law-compliance#shop-redact) ### Simulate an event using the command line You can use the CLI to simulate specific events occurring on a shop. This lets you test your processing logic by sending a POST request to your endpoint with a synthetic webhook. Note that it does not test your subscription configuration! [`shopify app webhook trigger`](https://shopify.dev/docs/api/shopify-cli/app/app-webhook-trigger) The address inputted for the `--address` flag should follow the following format: ``` pubsub://{project-id}:{topic-id} ``` {/* STEP 5.2: EVENTBRIDGE */} ## Test your subscription ### Use Cloudwatch to ensure you can see the webhooks coming through 1. Copy and paste your event bus URL (this is your ARN). 1. Navigate to CloudWatch > Live tail. 1. Select EventBridge. ### Manually trigger an event in your test shop Most webhook topics will fire immediately if you trigger the corresponding event your dev store. 1. Navigate to your test shop and create a new order. 1. The webhook payload should appear in your Cloudwatch Live tail console. A small number of webhook topics will not fire immediately if you trigger an event in your test shop. They include: - The [customers/redact topic](/docs/apps/build/privacy-law-compliance#customers-redact) - The [shop/redact topic](/docs/apps/build/privacy-law-compliance#shop-redact) ### Simulate an event using the command line You can use the CLI to simulate specific events occurring on a shop. This lets you test your processing logic by sending a POST request to your endpoint with a synthetic webhook. Note that it does not test your subscription configuration! [`shopify app webhook trigger`](https://shopify.dev/docs/api/shopify-cli/app/app-webhook-trigger) The address inputted for the `--address` flag should be your ARN. You can find details in your Amazon EventBridge console: **Partner Event Sources** > **Select your event source** > **Partner event source ARN**. This the same format as the URI you specified in your app configuration file. {/* STEP 5.3: HTTPS */} ## Test your subscription ### Manually trigger an event in your test shop Most webhook topics will fire immediately if you trigger the corresponding event your dev store. 1. Navigate to your test shop and create a new order. 1. The webhook payload should print to your CLI. A small number of webhook topics will not fire immediately if you trigger an event in your test shop. They include: - The [customers/redact topic](/docs/apps/build/privacy-law-compliance#customers-redact) - The [shop/redact topic](/docs/apps/build/privacy-law-compliance#shop-redact) ### Simulate an event using the command line You can use the CLI to simulate specific events occurring on a shop. This lets you test your processing logic by sending a POST request to your endpoint with a synthetic webhook. Note that it does not test your subscription configuration! [`shopify app webhook trigger`](https://shopify.dev/docs/api/shopify-cli/app/app-webhook-trigger) The address inputted for the `--address` flag should be the HTTPS server URL or the URL provided through the mock server site. ## Tutorial Complete! Congratulations! You subscribed your app to a webhook topic using Remix, Google PubSub, and Shopify webhooks. Keep the momentum going with these related tutorials and resources. ### Next steps #### Deploy your app Follow our guide to deploy your Remix app to a testing or production environment. #### Explore the Shopify Webhooks reference Explore the Webhooks reference to learn about the full list of topics Shopify has, required access and approval scopes, and sample payloads. #### Learn about customizing your webhooks Customize your webhooks experience by using filters or modifying the payload per webhook. #### Select an app distribution method Decide how you want to share your app with users. For example, you might make your app available in the Shopify App Store, and bill customers for usage.