Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
Node.js/Express
So I programatically created a webhook via the orders/create webhook.
I also used the GET request to check and make sure there are no other webhooks created by the API from past development attempts.
This is the endpoint I use to receive data (example):
receiveWebhookData: function(req, res) {
res.status(200).end(); // Tell Shopify I've successfully received their webhook data.
console.log(res.data); // To see the new order created data from webhook.
}
I've read in the documentation somewhere that I have to send a 200 successful status code as a response. So I did just that. However, I still receive data from the webhook from the sample order I placed via my development test shop (that I only have access to and no one else).
How do I stop them from sending me duplicate data that I've received the first time around (even though I sent them the 200 response - unless I'm doing it wrong...)?
Thank you.
You have to assume your queue will have N copies of the same webhook. So yes, you return 200 OK, but that does not mean you will receive zero dupes. The reason is, Internet. Nothing is instant. By the time you got the payload, and responded with 200 OK, Shopify may have sent another copy.
option 1: Use a queue. Pop off the entry. Have you done it before? Throw it out.
option 2: set a key in a cache for the webhook. if when you're processing the hook, you notice you already saved the ID, stop.
And others...
So you have to choose to do something.
Ah, glad to know I'm doing it right and that it was just due to natural network reasons.
Yes, my intent is to use a queue.
I was hoping I could avoid checking for duplicates, but I guess not.
Thank you very much for the response @HunkyBill !
Shopify offers a new service for webhooks using Amazon that might just have all you need, built-in, ready to go. Check that out too.
@HunkyBill What is the name of the service? Are you talking about EventBridge?
I also got the same issue of getting duplicate Webhook on create/order. Although I return 200 (ok) via C# code, it failed to do so. The more painful issue is that after 48 hours Shopify delete my webhook over the issue of
Your webhook for orders/create at https://doamin/SORC/api/Order/OrderCreation is failing to return a successful response.
This webhook has been attempted 2 times. If your webhook continues to fail, it will be removed and your application will not receive any more notifications.
Yes, they called it EventBridge. I have not used it, but supposedly it works!
It makes no difference that you returned a 200 OK if you took too long to return 200 OK... do your logs show how long it took it to return 200 OK? 150ms? 1500ms? 15000ms? When Shopify sends a webhook out, the infrastructure does not wait around forever for the 200 OK. And since you are getting messages from Shopify saying they are not getting 200 OK, it reveals that while you may think you are returning 200 OK, you probably are not. Check your logs!