Order Creation Webhook submitting multiple times

Order Creation Webhook submitting multiple times

avanlaningham
Visitor
1 0 0

I work as an internal developer for a company with a shopify store front and have written a custom application to sync our shopify orders with our internal order management system. The entire thing is based around the "Order Creation" webhook calling on an endpoint to kick off the process. It's working reasonably well. 

 

Recently we've noticed an influx of duplicate orders into our system. The system still relies on human interaction for final approval, so thankfully none of our customers have been charged or actually received double orders. However, the problem appears to be caused by the webhook for "Order Creation" being called twice on some orders. There appears to be no firm commonality I can find between the orders that cause the webhook to fire twice and the orders that do not. 

Anyone else have an issue with the order creation webhook? 

Replies 2 (2)

Liam
Shopify Staff
2873 312 821

Hi Avanlaningham,

Just to confirm - is your custom app sending back a 200 status code when it successfully receives an Order created event? In our webhook best practices guide, we do advise to set up your app to ignore duplicate calls by using idempotent operations - this means even if you receive the same webhook event a second time it should have no additional effect. You can detect duplicate webhook events by looking for identical X-Shopify-Webhook-Id headers, or by comparing the payload directly to the previous state. 

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

tyuzu
Shopify Partner
20 0 0

Hello Mr. @Liam , I'm also trying to implement the this to ignore duplicates. But I having hard time understanding the receievedWebhooks . Do I need to import it? If yes, how ? I don't know path should I use and I can't find it also on the documentary.

 

Or it just a normal JavaScript approach ? like using the new Set() ?

 

For example, you could use a callback function to check if the webhook (webhookId) has already been received by looking it up in the receievedWebhooks object.