Solved

Keep webhook register on authentication after server restart.

anjrot
Tourist
3 1 0

Hi everyone, i just making a public app but a get some problems with the webhooks. I create a webhook register in the app authentication and everything is ok, but after any server restart i lost my webhooks installation. So my question is, how may i keep a webhook registered in my app after a server restart. i've been using the new @Shopify/shopify-api package, and the way i've been registering webhooks is like this tutorial "https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react/listen-for-store-events-with-w.... I hope you can help me in order to finish my app.

Regards

Accepted Solutions (2)

nir2002
Visitor
1 1 3

This is an accepted solution.

Hi friend, all you need to do is re-register the webhooks handlers when your server restarts, like this:

Shopify.Webhooks.Registry.webhookRegistry.push({path: "/webhooks", topic: "ORDERS_PAID", webhookHandler: ordersPaidHandler});

 

Its discussed widely here, you can skip to the answer in this part of the discussion.

It's also mentioned in the documentation in the "Note" part, although it's not very informative and without an example.

 

Hopes this helps!

View solution in original post

anjrot
Tourist
3 1 0

This is an accepted solution.

Hi @nir2002, thank you so much for this extremely usefull answer, i'm going to implement this snippets and see if it works, again thank you so much

Regards

Anjrot

View solution in original post

Replies 5 (5)

anjrot
Tourist
3 1 0

After some days trying to understand how the connection to webhooks with the package @Shopify/shopify-api, i just returned to the old fashion way with the @Shopify/koa-shopify-webhooks, the problem is that after register a new webhook with the new implementation the webhookHandler inside the Shopify.webhooks.Registry.register do not work after a server restart. With the Koa-shopify-webhooks i can use the middleware receiveWebhook, it allows me to trigger the webhook no matter what i had restarted the server.

Let me know how to do this with the shopify-api package, i like to always use your new things

regards

Anjrot

nir2002
Visitor
1 1 3

This is an accepted solution.

Hi friend, all you need to do is re-register the webhooks handlers when your server restarts, like this:

Shopify.Webhooks.Registry.webhookRegistry.push({path: "/webhooks", topic: "ORDERS_PAID", webhookHandler: ordersPaidHandler});

 

Its discussed widely here, you can skip to the answer in this part of the discussion.

It's also mentioned in the documentation in the "Note" part, although it's not very informative and without an example.

 

Hopes this helps!

anjrot
Tourist
3 1 0

This is an accepted solution.

Hi @nir2002, thank you so much for this extremely usefull answer, i'm going to implement this snippets and see if it works, again thank you so much

Regards

Anjrot

GR1998
Shopify Partner
1 0 0

its Worked for me, thanks

jdevmanzo
Shopify Partner
5 0 2

I can't thank you enough for this. Thank you so much. This fixed an issue I had for months in my app.