Jodo1992 Jodo1992 - 1 year ago 50
JSON Question

Why does $status = 0 After Using curl_exec($curl)?

I'm trying to create a recipientView using the DocuSign API. I'm trying to POST a request in PHP using the cURL library but for some reason when executing my code, the line

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
in my code below is returning 0:

$url = "$account_id/envelopes/

$body = array("returnUrl" => "",
"authenticationMethod" => "None",
"email" => "$recipient",
"userName" => "$recipient");

$body_string = json_encode($body);

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
'Content-Length: '.strlen($body_string),
'Authorization: Bearer '.$access_token
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body_string);

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

echo $status;

$response = json_decode($jason_response, true);
$url = $response["url"];

I am sending the POST via JSON and the response I am supposed to get back is JSON. Why is it that my
is failing and making
$status = 0

kb. kb.
Answer Source

The reason for your error message

Failed to connect to port 80: Connection refused

Is that you are attempting to connect to HTTP port 80 but only listens to HTTPS port 443.

Change API URL from http:// to https:// and you should be set and the curl_getinfo() will return the correct value as well.