4

I've pasted my code below. I'm getting an empty string back, no curl error or anything.

$service_url = "https://api.insight.ly/v2.1/Opportunities";           
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "-my-base64-encoded-api-key");

$data = curl_exec($ch);
curl_close($ch);

since the documentation for the Insightly API said to leave password blank, i've also tried

 curl_setopt($ch, CURLOPT_USERPWD, "-my-base64-encoded-api-key:"); 

and

 curl_setopt($ch, CURLOPT_USERPWD, "-my-base64-encoded-api-key: ");

Any help would be appreciated. Thank you.

Grokify
  • 15,092
  • 6
  • 60
  • 81
Gratus D.
  • 787
  • 7
  • 22
  • 1
    based on this: https://api.insight.ly/V2/Help/ApiController/Opportunities your url is not valid, there's more to add –  Oct 24 '13 at 23:07
  • Hi Dagon - this url:https://api.insight.ly/v2.1/Help/Introduction gives the "v2.1" as the url for their service. – Gratus D. Oct 28 '13 at 18:50

1 Answers1

7

Below is the working code - I had to send the authorization in the header, not as an option in CURL. I didn't know this was possible. Insightly support came through and provided me with additional instructions. I am posting the answer below in case someone else runs into this problem.

$service_url = 'https://api.insight.ly/v2.1/Opportunities';
$ch = curl_init($service_url);           
curl_setopt($ch, 
            CURLOPT_HTTPHEADER, 
            array('Content-Type: application/json', 
                  'Authorization: Basic my-base64-encoded-api-key'));
curl_setopt($ch , CURLOPT_HEADER, 0);           
curl_setopt($ch , CURLOPT_TIMEOUT, 30);           
curl_setopt($ch , CURLOPT_HTTPGET, 1);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, TRUE);            

$return = curl_exec($ch );    

curl_close($process);
Gratus D.
  • 787
  • 7
  • 22
  • When I try to use this code, I keep getting 404 error. – Red2678 May 25 '14 at 14:03
  • Is your API access set up properly? 404 error looks like your connection attempt is being dropped by their firewall. My guess is that maybe you have an error in the API key you are using. – Gratus D. Jun 05 '14 at 18:57