Why is my webhook failing to return a successful response?

Why is my webhook failing to return a successful response?

vineetgupta
Shopify Partner
7 1 3

Hello 

 

I have created a webhook using the curl function.

It is showing me errors like this.

 

Anyone, please let me know.

 

Your webhook for fulfillments/update at https://.../updatefulFillMentWehook 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.

 

 

 

Here is my code.

 

 

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL =>  $curl_url_webhooks,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\r\n\t\"webhook\" : {\r\n\t\t\t\"topic\" : \"fulfillments\/update\",\r\n\t\t\t\"address\": \"https://...../updatefulFillMentWehook\",\r\n\t\t\t\"format\": \"json\"\r\n\t}\r\n}",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache",
    "content-type: application/json",
    "postman-token: 903957eb-e03a-95ae-da3d-92b8c061d936",
    "x-shopify-access-token: ".$curl_token
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
 // echo "cURL Error #:" . $err;
} else {
 // echo $response;
}

 

 

Can you please help anyone with this?

 

Thanks

 

 

 

Reply 1 (1)

Kani
Shopify Partner
468 125 232

Hi @vineetgupta 

 

Is that all code?

Then you have not return anything to webhook.

if ($err) {
 // echo "cURL Error #:" . $err;
} else {
 // echo $response;
 return json_encode(array(['msg'=>'success']));
}

 

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂