Connecting to Invoice Ninja's API using CURL and PHP

Invoice Ninja hello. I’m trying to connect to your API using a CURL request. The current iteration of my code is lifted straight from your very own SDK wrapper (specifically the sendRequest method in bstractModel.php). This is how it looks:

	$type = 'GET';
	$token = 'myTokenGoesHere'; 
	$curl = curl_init();
	    $opts = [
	        CURLOPT_URL => 'https://app.invoiceninja.com/api/v1/clients',
	        CURLOPT_RETURNTRANSFER => TRUE,
	        CURLOPT_CUSTOMREQUEST => $type,
	        CURLOPT_POST => $type === 'POST' ? 1 : 0,
	        CURLOPT_HTTPHEADER  => [
	            'Content-Type: application/json',
	            'X-Ninja-Token: '. $token,
	        ],
	    ];
    curl_setopt_array($curl, $opts);
    $response = curl_exec($curl);
	curl_close($curl);

This call is supposed to return a list of all the customers, but instead is returning Boolean false. I know my token is correct because I’m able to view correct results when using CURL from the command line. However, it does not work using the above PHP code. Can you please have a look and let me know if I’m missing something here?

I’m not sure, the code is working for me.

I’d suggest checking for any curl errors with curl_error($curl);

Thank you for your swift reply. I did as you suggested and the resulted output was:

CURL Error: SSL certificate problem: unable to get local issuer certificate

This makes sense, because I’m currently working locally using XAMPP and indeed do not have a valid SSL certificate. Is there an HTTP protocol request URL one can use for development purposes?

Maybe this will help…

https://stackoverflow.com/a/34883260/497368

I was able to force the CURL request to ignore the lack of an SSL certificate by adding CURLOPT_SSL_VERIFYPEER => FALSE, to the $opts array. Thank you for the help!

Glad to hear you got it working, thanks for sharing your solution!