Keep webhook register on authentication after server restart.

Solved
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

0 Likes
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

0 Likes
nir2002
New Member
1 1 1

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

0 Likes