App reviews, troubleshooting, and recommendations
I'm trying to extend the code provided by the Shopify CLI for app creation and able to get webhook notifications from Shopify.
app.post( shopify.config.webhooks.path, shopify.processWebhooks({ webhookHandlers: GDPRWebhookHandlers }) ); GDPRWebhookHandlers file import { DeliveryMethod } from "@shopify/shopify-api"; export default { CUSTOMERS_DATA_REQUEST: { deliveryMethod: DeliveryMethod.Http, callbackUrl: "/api/webhooks", callback: async (topic, shop, body, webhookId) => { const payload = JSON.parse(body); console.log(payload) }, }, CUSTOMERS_REDACT: { deliveryMethod: DeliveryMethod.Http, callbackUrl: "/api/webhooks", callback: async (topic, shop, body, webhookId) => { const payload = JSON.parse(body); }, }, SHOP_REDACT: { deliveryMethod: DeliveryMethod.Http, callbackUrl: "/api/webhooks", callback: async (topic, shop, body, webhookId) => { const payload = JSON.parse(body); }, }, PRODUCTS_UPDATE: { deliveryMethod: DeliveryMethod.Http, callbackUrl: "/api/webhooks", callback: async (topic, shop, body, webhookId) => { const payload = JSON.parse(body); console.log('PRODUCTS_UPDATE', payload); }, }, };
What do I need to do to set up a webhook that fires when a product changes and so that I can get information about the changed product?
As I see you already added the new webhook you want to subscribe to and added the callback function to it. You just have to uninstall and install again the app, so the webhook subscription can be made by the app.
Adding onto what @Spring_Season said. You are only adding the route and is ready to listen, but you haven't registered the webhook yet. Unfortunately listing the webhooks in the GDPRWebhookHandlers file will only "automatically" register on installation.
This is fine if you have a simple app and never really upgrade. But if you do you'll have to register the webhook.
const callbackResponse = await shopify.auth.callback({ rawRequest: req, rawResponse: res, });
const response = await shopify.webhooks.register({ session: callbackResponse.session, });
I found the snippet here in their docs. Setting up webhooks
Sorry, the link was broken. Here it is again
https://github.com/Shopify/shopify-api-js/blob/main/docs/guides/webhooks.md
So, let's say I want to add a Webhook for when the user uninstalls the app, it will be okay to add it on the GDPRWebhooksHandlers Right?
Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024Note: Customizing your CSS requires some familiarity with CSS and HTML. Before you cust...
By JasonH Aug 12, 2024