Problem getting position data

PeteEis7 years ago

Hi.

After upgrading to the new 3.16, I got a problem with using the api for getting position data.
When I try to call the api with php code:

function getLastPosition($posID){
global $authentication;
 	$curl = curl_init();
	$url = "http://192.168.1.121:8082/api/positions?id=$posID";

	curl_setopt_array($curl, array(
		CURLOPT_URL => $url,
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => "",
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 30,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => "GET",
		CURLOPT_HTTPHEADER => array(
    "authorization: Basic " . $authentication , 'Content-Type: application/json',  
  ),
));

where $authentication = base64_encode("username:password");, I get the error message NullPointerException (PositionResource:90 < ...).

I have been using the same code on the 3.15 version without any problems.
Also I am able to get data using "api/devices", it is only when I try to get positions, that I get this error.

Do you have any idea of what causes this?

Anton Tananaev7 years ago

You need to include Accept header in your request.

PeteEis7 years ago

Hi Anton.
Thanks for your quick reponse.

Adding the Accept header to the request

CURLOPT_HTTPHEADER => array(
    "authorization: Basic " . $authentication , 'Content-Type: application/json', 'Accept: application/json),

fixed the problem.

Funny that the same code worked on the 3.15 version.