Search code examples
phpcurlzendesk

CURL function returns null in php


I am trying to fetch some data from my zendesk account as follows:

$ch = curl_init();
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
        curl_setopt($ch, CURLOPT_URL, "https://testing136.zendesk.com/api/v2/users/me.json");
        curl_setopt($ch, CURLOPT_USERPWD, "[email protected]/token:apikey");
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
        curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        $output = curl_exec($ch);
        curl_close($ch);
        $decoded = json_decode($output);
        print("Decode ".$decoded);

I have double checked the parameters and data but nothing is returned. I just get Null although I tried to curl in the cmd and it was done successfully.

Any help would be really appreciated.


Solution

  • please add

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);