shopify/koa-shopify-webhooks 200 response

reecewilliams
Tourist
6 0 2

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

Replies 4 (4)

hassain
Shopify Staff (Retired)
624 104 187

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.

reecewilliams
Tourist
6 0 2

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
mpeapps
Shopify Partner
2 0 0

Did you resolve this in the end @reecewilliams ?

Have the same exact issue.

dgtlmonk
Shopify Partner
38 3 7

same issue. halp!