Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
Hi everyone.
Im a brand new shopify dev.
Im building an app and I need to call our already built backend every time theres a product update on a given shop.
This seems to be the code for it: (which works but doesnt.....)
const response2 = await Shopify.Webhooks.Registry.register({
path: "/webhook",
topic: "PRODUCTS_UPDATE",
accessToken,
shop,
webhookHandler: () => true,
});
if (!response2.success) {
console.log(
`Failed to register PRODUCTS_UPDATE webhook: ${JSON.stringify(
response
)}`
);
}
`/webhook` is relative to the URL that this app runs under... (local tunnel or ngrock or a given URL when its deployed)
what if I want to call another server instead? Its just me or thats not a thing? because after all `/webhook` is turned into https://my-app.loca.lt/webhook here: https://github.com/Shopify/shopify-node-api/blob/975b87985c57cc723488a9f712de39a28ce2c967/src/webhoo...
what I mean to do is:
const response2 = await Shopify.Webhooks.Registry.register({
path: "https://MY-SERVER.com/webhook",
topic: "PRODUCTS_UPDATE",
accessToken,
shop,
webhookHandler: () => true
});
if (!response2.success) {
console.log(
`Failed to register PRODUCTS_UPDATE webhook: ${JSON.stringify(
response
)}`
);
}
but this doesnt seem to be working....
something tells me this isnt possible but it should be since theres another non programmatic way of doing the webhooks which literally asks/accepts an URL:
https://help.shopify.com/en/manual/orders/notifications/webhooks
Looking at the library source code:
https://github.com/Shopify/shopify-node-api/blob/main/src/webhooks/registry.ts
It looks like I should be able to pass `deliveryMethod: DeliveryMethod.Http,` but if thats the method it will build the URL for me on line 276....
Welp?! 🤔😂
Solved! Go to the solution
This is an accepted solution.
From what I figured currently there isnt a way to specify the full path using the shopify library.
So what I ended up doing was saving the access token and making the request from our backend.
Hello, @rodrigograca31 ! Welcome to the developer community.
There are two ways to create webhooks at Shopify:
I think looking into #2 will help you get started down the application path, since #1 is for a very different use case for individual merchants. https://shopify.dev/apps/webhooks May also be useful to get an idea of what webhooks are and how they work.
Hopefully this can help you get started!
To learn more visit the Shopify Help Center or the Community Blog.
This is an accepted solution.
From what I figured currently there isnt a way to specify the full path using the shopify library.
So what I ended up doing was saving the access token and making the request from our backend.
Hi James,
Could you tell me if it's possible to add an option { url: string } in the method Shopify.Webhooks.Registry.register. This will be so helpful especially in a case when you want to trigger your webhook in external server.