Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
I'm getting an issue with koa shoipify webhooks where I receive the same APP_UNINSTALL webhook multiple times.
My understanding of the issue is that I should be returning a 200 response code to let Shopify know I have received the call, however I can't see how this is done via the documentation on NPM. For reference my code is:
receiveWebhook({ path: '/webhooks/uninstall', secret: [SHOPIFY_API_SECRET_KEY], // called when a valid webhook is received async onReceived(ctx) { console.log('received webhook: ', ctx.state.webhook.topic); try { // REMOVE STORE DATA HERE } catch (e) { console.log('an error occured deleting a store') } console.log('completed uninstall') return }, }), );
I have tried adding "ctx.res.statusCode = 200;" "ctx.res.status = 200;" "ctx.status = 200;" "return true" and all variations in between.
I am receiving the hook as I see all console logs through the handler.
Any help would be greatly appreciated.
Hi @reecewilliams ,
I believe for Koa the syntax is "ctx.response" not "ctx.res". You should be able to respond to webhook notifications in Koa with a 200 response by setting `ctx.response.status=200` or setting `ctx.response.body = {any non null value}. If response.status has not been set, but response.body is not null, then Koa will automatically set the status to 200 or 204. As well, you can also try `ctx.throw(200)` to automatically respond with a 200, or any other error code you want.
Helpful documents about Koa can be found here: https://github.com/koajs/koa/blob/master/docs/api/response.md and https://devhints.io/koa
To learn more visit the Shopify Help Center or the Community Blog.
Thanks for getting back to me @hassain
I'm still getting the issue with
ctx.response.body = 'successful'
ctx.response.status = 200
throw(200)
same issue. halp!