Google Cloud Pub/Sub webhook delivery
Tracking traffic from Shopify's platform can be overwhelming, especially as you grow your app. Integrating with Google Cloud Pub/Sub allows your app to consume events at its own pace and handle large volumes of webhook traffic.
This tutorial shows you how to use Google Cloud Pub/Sub to manage webhook events for your app.
Shopify has verified support for Google Cloud Pub/Sub, but hasn't verified support for Pub/Sub Lite.
Requirements
Anchor link to section titled "Requirements"- You've created an app.
- You've set up a Google Cloud Pub/Sub project.
- You've created at least one topic in the project.
For more information on creating projects and topics, refer to Google's Pub/Sub quickstart guide.
Step 1: Integrate your app with Google Cloud Pub/Sub
Anchor link to section titled "Step 1: Integrate your app with Google Cloud Pub/Sub"To integrate your app with Google Cloud Pub/Sub, you need to get the Shopify service account address from the Partner Dashboard, and then add that address to a Google Cloud Pub/Sub topic.
Get the Shopify service account address
Anchor link to section titled "Get the Shopify service account address"- Go to your Partner Dashboard.
- Go to Apps, and then click the name of your app.
- Click Configuration.
- In the App settings section, under Google Cloud Pub/Sub, copy the Shopify service account address.
Add the service account address to Google Cloud Pub/Sub
Anchor link to section titled "Add the service account address to Google Cloud Pub/Sub"- In the Google Cloud Console, go to Pub/Sub > Topics.
- Next to a topic, click
⋮
and then click View permissions. - Click ADD PRINCIPAL.
- Paste the Shopify service account address into the New principals text box.
- In the Role drop-down list, select Pub/Sub and Pub/Sub Publisher.
- Click Save.
You can now add webhook subscriptions to the Google Cloud Pub/Sub topic using Shopify's APIs.
Step 2: Subscribe to webhooks using GraphQL and Google Cloud Pub/Sub
Anchor link to section titled "Step 2: Subscribe to webhooks using GraphQL and Google Cloud Pub/Sub"After you've integrated your app with Google Cloud Pub/Sub, you can use GraphQL mutations to subscribe to, update, and delete webhook subscriptions.
Create a new webhook subscription using GraphQL
Anchor link to section titled "Create a new webhook subscription using GraphQL"To create a new webhook subscription using GraphQL and Google Cloud Pub/Sub, you can use the pubSubWebhookSubscriptionCreate
mutation, as shown in the following example. When using this mutation, set pubSubProject
to the ID of your Google Cloud Platform project, and set pubSubTopic
to the ID of the topic you set up in Google Cloud Pub/Sub.
POST /admin/api/2024-07/graphql.json
Update webhook subscriptions using GraphQL
Anchor link to section titled "Update webhook subscriptions using GraphQL"To update a Google Cloud Pub/Sub webhook subscription using GraphQL, you can use the pubSubWebhookSubscriptionUpdate
mutation, as shown in the following example. When using this mutation, set pubSubProject
to the ID of your Google Cloud Platform project, and set pubSubTopic
to the ID of the topic you set up in Google Cloud Pub/Sub.
POST /admin/api/2024-07/graphql.json
Delete webhook subscriptions using GraphQL
Anchor link to section titled "Delete webhook subscriptions using GraphQL"You can delete webhook subscriptions for Google Cloud Pub/Sub using the webhookSubscriptionDelete
mutation.
Step 3: Subscribe to webhooks using REST and Google Cloud Pub/Sub
Anchor link to section titled "Step 3: Subscribe to webhooks using REST and Google Cloud Pub/Sub"After you've integrated your app with Google Pub/Sub, you can use REST requests to subscribe to, update, and delete webhook subscriptions.
Create a new webhook subscription using REST
Anchor link to section titled "Create a new webhook subscription using REST"Subscribing to a webhook using the REST API and Pub/Sub is similar to subscribing to an HTTP webhook, but you set the address
field to pubsub://{project-id}:{topic-id}
, where {project-id}
is the ID of your Google Cloud Platform project, and {topic-id}
is the ID of the topic you set up in Google Cloud Pub/Sub.
POST https://{store_name}.myshopify.com/admin/api/2024-07/webhooks.json
Update or delete webhook subscriptions using REST
Anchor link to section titled "Update or delete webhook subscriptions using REST"You can update webhook subscriptions and delete them by ID using the Webhook resource.
Google Cloud Pub/Sub payloads
Anchor link to section titled "Google Cloud Pub/Sub payloads"When you're using Google Cloud Pub/Sub to manage your webhooks, you receive a JSON payload for topics as described in the Webhook resource documentation. However, unlike with an HTTP webhook, you don't need to perform HMAC verification.
Refer to the Google Cloud Pub/Sub documentation for payload size limits.
- Learn how to configure a webhook for your app and manage webhooks for different API versions.
- Set up the mandatory webhooks that your app requires.
- Consult the GraphQL Admin API or REST Admin API reference for the complete list of supported webhook topics.