Rest API webhook firing too many times

Rest API webhook firing too many times

Alex_Adamczyk
Visitor
3 0 0

Hello, 

I have a webhook subscription set up in the notifications section of the admin panel for the orders/create event. 
Everything seems to be working fine, except for the fact that the webhook gets fires multiple times for each created order (anywhere form 2-5 times from what I've seen so far). 
I also have a make.com scenario set up with the same webhook event subscription and it only gets fired once per created order as expected.

Does anyone know why this would happen? Obviously I can just connect the url I have set up for my webhook on shopify to the make scenario, but I'd like to avoid having extra steps in the process unless its strictly necessary. 

 

Thank you 

Replies 3 (3)

james598grose
Visitor
1 0 0

Hi @Alex_Adamczyk ,

It sounds like you're experiencing an issue where your webhook for the `orders/create` event in Shopify is firing multiple times for a single order, which is definitely frustrating. Here are a few things that could be causing this and some potential solutions:

### Possible Causes and Solutions:

1. **Multiple Webhook Subscriptions:**
- **Check for Duplicate Webhooks:** In the Shopify admin panel, ensure that you don’t have multiple webhooks subscribed to the same `orders/create` event. If there are duplicates, they could all be triggering simultaneously, causing multiple notifications.

- **Different Apps Hooking into the Same Event:** If you have multiple apps installed that listen to the same `orders/create` event, they could be causing additional triggers. Check the integrations you have connected to your store.

2. **Webhook Retries:**
- **Retries Due to Failures:** Shopify automatically retries webhook notifications if it doesn’t receive a `200 OK` response from your server. Make sure your webhook endpoint is correctly responding with a `200 OK` status to acknowledge successful receipt. Otherwise, Shopify will assume the webhook has failed and retry it, leading to multiple notifications.

- **Logs and Monitoring:** Check your server logs to see if Shopify is indeed retrying the webhook due to non-`200 OK` responses.

3. **Order Changes/Events:**
- **Partial Orders or Subsequent Updates:** Shopify might send multiple webhooks if the order undergoes any updates shortly after being created, such as changes to payment status, fulfillment, or inventory adjustments. Check if there are any immediate actions following the order creation that might trigger additional events.

4. **Rate Limiting/Concurrency Issues:**
- **Concurrency on Your Webhook Handling Side:** If you have multiple server instances or load balancing, there could be concurrency issues causing the webhook to fire multiple times. Ensure that your webhook handler is designed to handle idempotency, meaning it should be able to process the same webhook event only once, even if it’s received multiple times.

### How to Handle Multiple Webhook Calls:
- **Deduplicate Webhooks on Your Side:** If Shopify is sending the webhook multiple times, implement logic in your webhook handler to check whether the order has already been processed. This can be done by keeping a record of processed order IDs and ignoring duplicates.

- **Shopify Support:** If none of the above works, you may want to reach out to Shopify Support for further investigation, as this could be an issue specific to your store setup.

By addressing these points, you should be able to reduce or eliminate the multiple webhook calls.

Let me know if you need any further assistance!
Official Website

Best Regards
james598grose

Alex_Adamczyk
Visitor
3 0 0

Thank you for your detailed response. 

The issue possibly stems from the non 200 OK response retries. I've implemented a solution which should resolve the problem.
Could you please point me to the article detailing the structure of the response structure that the shopify server expects?
So far I've set it up as {"status": 200} based on someone else's code, but I'm not sure whether it's correct.

Alex_Adamczyk
Visitor
3 0 0

One other thing I should mention - when a client pays for the order via COD the webhook gets fired a few times (as usual) and usually at least one of the webhook payloads doesn't contain the COD line item (as it should and as it does in the other webhook payloads)