In my server.js file, I register the app/uninstalled webhook inside the afterAuth function like this:
const response = await Shopify.Webhooks.Registry.register({
shop,
accessToken,
path: "/webhooks",
topic: "APP_UNINSTALLED",
apiVersion: ApiVersion.October20,
webhookHandler: (topic, shop, body) => {
//console.log(topic, shop,body);
delete ACTIVE_SHOPIFY_SHOPS[shop];
},
});
I am listening to route like this
router.post("/webhooks", appUninstallWebhook, async (ctx) => {
try {
await Shopify.Webhooks.Registry.process(ctx.req, ctx.res);
console.log(`Webhook processed, returned status code 200`);
} catch (error) {
console.log(`Failed to process webhook: ${error}`);
}
});
I see the webhook successfully being registered, however when I delete the app running locally on ngrok in my test Shopify store, I do not see that webhook being triggered.
Any help would be really helpful.
3
Answers
Unfortunately, I couldn't get it working but I got a workaround using another approach.
And then configure the route
You can try to register
APP_UNINSTALLED
webhook in /auth/callback route of your shopify app i.e during oauth process register your webhook.Sample code:
I was able to make it work properly after I noticed the line "app.use(express.json());" was above the webhook definition while it needs to be below of it, according to Shopify instructions.