0
votes

In my shopify store I have setup an order creation webhook. The webhook points to a Cakephp action URL which receives the data from webhook as following:-

$content = file_get_contents ( "php://input" );

After that it is saving this order data to the app database as:-

$orderData =array('order'=>$data['order_number'],'details'=>$content);
$orders = new Order ();
$orders->saveall($orderData);

Now the issue is that for each single order created the webhook is getting invoked multiple times. Although it performs the necessary action in the first attempt, yet Shopify is not able to identify the call success and is getting it invoked again and again until the limit reaches. After the limit is reached the webhook is getting deleted from the store.

My question is that do we need to send any type of status or response to the webhook call after it performs the necessary action. Because it is not very clear from shopify webhook documentation. They state that webhook call success is determined from HTTP status 200. How can I check what is the status returned by a webhook call? How can I make sure that Shopify is informed of webhook success through my app code and it does not invokes further calls to the webhook?

2
Are you returning a http status of 200 to your calling method from shopify?Colonel Mustard
No I am just doing the require functionality but not specifically returning the status. Do I need to send it to be something like:- header("HTTP/1.1 200 OK"); or echo json_encode(array()); ?Savina Chandla
Well, you say that the documentation states that the webhook call success is determined from HTTP status 200 then the first thing I would try is returning a 200Colonel Mustard
I have added the following code to my script:- header("HTTP/1.1 200 OK"); $status=array(); $status['status'] = '200'; echo json_encode($status);. But still no success, the webhook is still getting called multiple timesSavina Chandla
There is also a 5 second response time limit. If your processing is lengthy you'll need to put the order info into a queue and process it after the webhook returns.bknights

2 Answers

2
votes

Yes, you need to send a 200 response to Shopify within a short time 5s. Otherwise, Shopify will send a request in a short time.

The official guide suggests that you store the webhook data and process it with a queue, thread, or whatever ways you preferred. After that, you return a 200 response to Shopify immediately.

IMO, if there are many webhook requests sending to you, it's better to separate the webhook receiver from your app server. You can do it with AWS Lambda or docker swarm so that the webhook requests won't break your app server.

Source:

  1. Time limit: enter link description here
  2. Webhooks with AWS Lambda: enter link description here
1
votes

Just to clarify for others, you have to explicitly return a 2XX HTTP code or it'll retry 19 times over 48 hours, then delete your webhook if it exceeds that.