3

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.

5
  • Its probably due to a misseting in php config Commented Oct 23, 2014 at 10:25
  • @Etixpp could you clarify a bit more?! Commented Oct 23, 2014 at 10:26
  • 3
    curl_exec cannot return null. It returns false or, with RETURNTRANSFER enabled, the content. If nothing is returned, use curl_error to find out the problem. Commented Oct 23, 2014 at 10:26
  • 2
    I would btw if I were you VERY QUICKLY INVALIDATE THAT TOKEN that you copy/pasted in this code before everyone on Stack Overflow starts reading your Gmail. Editing it out here isn't enough since everyone can see the edit history, and about 10000 people can even see deleted topics. Commented Oct 23, 2014 at 10:28
  • @NielsKeurentjes I got the following SSL certificate problem: unable to get local issuer certificateDecode Commented Oct 23, 2014 at 10:34

2 Answers 2

4

please add

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Sign up to request clarification or add additional context in comments.

1 Comment

Could you explain about this and tell how we can improve the webserver to prevent adding this bypass? Anyway it saved my day, thanks a lot.
0

//Just Remove line no. 267 of application/libraries/REST_Controller.php in Codeigniter

header('Content-Length: ' . strlen($output)); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.