Jodo1992 Jodo1992 - 4 months ago 6
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 = "http://demo.docusign.net/restapi/v2/accounts/$account_id/envelopes/
$envelope_id/views/recipient";

$body = array("returnUrl" => "http://www.docusign.com/devcenter",
"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
curl_exec()
is failing and making
$status = 0
?

kb. kb.
Answer

The reason for your error message

Failed to connect to demo.docusign.net port 80: Connection refused

Is that you are attempting to connect to HTTP port 80 but docusign.net 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.