shopify/koa-shopify-webhooks 200 response

Highlighted
Tourist
6 0 1

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

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 103 124

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

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Tourist
6 0 1

Thanks for getting back to me @hassain 

 

I'm still getting the issue with 

ctx.response.body = 'successful'
and 
ctx.response.status = 200
Throwing 200 seemed to work, but that produced a depreciation warning, so I'm hesitant to use this method
throw(200)
Does the function need to return anything? (e.g. true, or ctx itself?)
 
Thanks,
Reece
 
Thanks,
Reece
0 Likes