Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Webhook firing multiple times

Webhook firing multiple times

reecewilliams
Tourist
6 0 2

Hi,

 

been struggling with this for a few days. 

 

I have an uninstall webhook, but it gets fired repeatedly. I'm using koa-shopify-webhooks package and I have the following code:

 

receiveWebhook({
      path: '/webhooks/uninstall',
      secret: [SHOPIFY-SECRET],
      // called when a valid webhook is received
      onReceived(ctx) {
        ctx.response.status = 200
        ctx.response.body = 'success'
        
        ctx.res.status = 200
        ctx.res.body = 'success'
        
        ctx.status = 200
        ctx.body = 'success'
        console.log('received webhook: ', ctx.state.webhook.topic,ctx.state.webhook.domain);
        
      },
    }),

As you can see I've tried multiple ways of setting the status and body of the response (all pulled from different documentation sources), however the repeated hooks persist.

 

I have previously console logged each before and after to ensure they were set correctly.

 

I am using an ngrok address currently for testing - just in case this is relevant. 

 

Looking at the ngrok logs it looks like it's still not returning the 200

 

Annotation 2020-05-04 112132.png

 

Thanks for any insight from koa veterans!

Replies 5 (5)

_JB
Shopify Staff (Retired)
836 100 223

Hey @reecewilliams,

 

Duplicate webhooks usually occur when your app takes too long (> 5s) to respond to Shopify, so it's assumed the delivery failed and Shopify retries. If you can provide the X-Request-ID from the request headers of a webhook that's fired more than once, I can check our logs to confirm.

JB | Solutions Engineer @ Shopify 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

traderkrut
Shopify Partner
8 1 6

Do webhook requests contain an `X-Request-ID` header? I don't it listed in the documentation, or when inspected locally.

https://shopify.dev/docs/admin-api/rest/reference/events/webhook?api[version]=2020-04

reecewilliams
Tourist
6 0 2

Hi @_JB 

 

I can't see an X-Request-ID on any of the webhook headers. Will this be anywhere else in the request? 

 

Thanks,

Reece

 

_JB
Shopify Staff (Retired)
836 100 223

Hey @reecewilliams @traderkrut ,

 

My apologies, looks like webhooks don't contain that header. If you can provide the resource id and an approximate timeframe from when you saw the duplicate, I can use that to find the result in our logs.

JB | Solutions Engineer @ Shopify 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

reecewilliams
Tourist
6 0 2

Thanks for looking into this @_JB 

 

The id passed was 

28881158218

There were several re-attempts around 3 hours ago.

 

Just to confirm, the koa package is returning with a 302 status code. My assumption is that this is throwing it off. Is this not the case?