[Solved] api/positions  

  RSS

JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 7 months ago
Posts: 28
24/04/2019 11:09 pm  

James,

I was using the gps::positions() funtion without problem.

Apparently something has changed in my traccar today, because I do not access anymore.

Searching on google, I found some reference to include "Accept" header in the request. I really don´t unsertand what it means or where I need change.  I need do/change something on PHP?

 

Today I use:

$sessionId = gps::$cookie;
$_SESSION['sessionId'] = $sessionId;
$z =gps::positions2($sessionId);
echo "<br> Devices: " . $response_z = $z->response; //para mostrar todo o array
echo "<br> Codigo: " . $response = $z->response;

 

the return is:

Devices: NullPointerException (PositionResource:90 < ...)
Codigo: NullPointerException (PositionResource:90 < ...)

is it possible help me? I'm a beginner in this programming.

 

 

JB

This topic was modified 6 months ago by JBFelizberto

Quote
jaimzj
(@jaimzj)
Guru Admin
Joined: 1 year ago
Posts: 58
24/04/2019 11:27 pm  

There are 2 possibilities.

1. Have you made any changes on traccar? or have you downgraded or upgraded it?

2. Have you made any change to the traccarApi.php file?

can you show me your function  positions2($sessionId);  in traccarApi.php

Markers & maps are magical !!!


ReplyQuote
JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 7 months ago
Posts: 28
24/04/2019 11:41 pm  

1. No, I am still using 4.3 (+/- one month). 

2. 

//Positions
public static function positions($sessionId){
return self::curl('/api/positions?'.$data,'GET',$sessionId,'',array());
}

public static function positions2($sessionId){
return self::curl('/api/positions?','GET',$sessionId,'',array());
}

public static function position($sessionId,$id){
$data='id='.$id;

return self::curl('/api/positions?'.$data,'GET',$sessionId,'',array());
}

Regards

JB


ReplyQuote
jaimzj
(@jaimzj)
Guru Admin
Joined: 1 year ago
Posts: 58
25/04/2019 2:22 am  

I don't see any problem in that code you shared. and it works for me, I just checked and it works flawlessly for me.

 

However if you want to check by adding 'accept' header. 

 

trying changing the 'array()'  part to 'array(self::$jsonC)'  or 'array(self::$jsonA)' try both these and see what happens for you.

Markers & maps are magical !!!


ReplyQuote
JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 7 months ago
Posts: 28
25/04/2019 2:47 am  

Works using 'array(self::$jsonA)' .   Thank you.

I will glad if you explain what is this  "self::$jsonA" . (for learning purpose)


ReplyQuote
jaimzj
(@jaimzj)
Guru Admin
Joined: 1 year ago
Posts: 58
25/04/2019 3:07 am  

scroll to the top of the 'traccarApi.php' file you will find  $jsonA and $jsonC the values assigned to it are headers / content type which is passed during the query to api

Markers & maps are magical !!!


ReplyQuote
Share:
  
Working

Please Login or Register