Webhooks sent twice

Highlighted
Shopify Partner
17 0 0

Hello, I see a forum on this topic from many years ago - not sure if it was resolved.  I am sending a test notification for an "Order creation" webhook and always receive TWO from Shopify.  They are almost at the same second even though I return a "200 OK" immediately.  Approx. 1 minute later ANOTHER one arrives ( all 3 are identical ).  Has this been resolved?  Should the response from me be just "200 OK" ( 6 characters ) or "200 OK" + Cr + Lf ( 8 characters ).  I've tried both, seems to make no difference.  I'm not sure if a real order does this, so far only sending a test.  Thanks!

0 Likes
Highlighted
Shopify Partner
17 0 0

Further to my post above, if I enter an order in my TEST store the webhook also fires more than once.  It's acting as though a "200 OK" was not sent so I must be doing this improperly.  Has anyone else experienced this?  The test and actual orders just keep coming.

0 Likes
Highlighted
Shopify Partner
46 0 9

Hi, any solution?

thanks

0 Likes
Highlighted
Tourist
7 0 1

Hello,

 

To respond back to Shopify webhooks to stop from sending more than once, you need to inform them with using a basic http/https method. In PHP, use a header function to respond back.

 

 Here is an example for PHP at the very top of the code:

 

$body = file_get_contents("php://input");
header("HTTP/1.1 200 OK");
...
http_response_code(200);

 

 

 

 "php://input" is one of the 2 methods which is listening for any data sending to this code and store it. (The second one is php://output, not revelent to this topic) This is what we will expect an incoming webhook from Shopify. And next, when we got it successfully, we want to send back with code 200 to inform we got it. I use a simple header like above. Or, you could do with HTTP/2.0 200. The 1.1 is the old basic HTTP while the 2.0 is secure but tougher to send and receive without pass security or authentication somethings.

Duplicate topics:https://community.shopify.com/c/Shopify-APIs-SDKs/Webhook-on-create-orders-called-twice/td-p/308676

 

Since your situation describes respond back with "200 OK" not work, I assume perhaps there are some steps missing as such http_response_code?

0 Likes