Consumindo a API

Dear, I am making an API call to return the trips.
/ reports / trips ........
however returns an xls file.
I need to return a JSON or other format for me to make a custom html report.
how do I do that?
thanks.

Anton Tananaev5 years ago

You need to specify accept header.

but I am informing the header

header('Content-Type: application/json');

sc_include_library("sys", "traccar", "traccar.php", true, true);

$username = 'jean.xxx@hotmail.com';
$password = 'xxxxxxxxxxxxxx';

$a = gps::login($username, $password);
$sessionId = gps::$cookie;
$_SESSION['sessionId'] = $sessionId;
$response = $a->response;
$responseCode = $a->responseCode;

if($responseCode == '200'){

    $deviceId 	= '9';
    $from 		= '2019-06-30T00:01:32Z';
    $to 		= '2019-06-30T23:59:32Z';
    
    $route = gps::reportTrips($sessionId,$deviceId,$from,$to);
    
    $rt = $route->response;

echo $rt;

}else{

    echo 'Incorrect username/password';
}
Anton Tananaev5 years ago

I don't see accept header in your code.

It's in class

class gps {

public static $host='http://127.0.0.1:8082';
private static $adminEmail='admin';
private static $adminPassword='admin';
public static $cookie;
private static $jsonA='Accept: application/json';
private static $jsonC='Content-Type: application/json';
private static $urlEncoded='Content-Type: application/x-www-form-urlencoded';

.....
.....
.....
}
Anton Tananaev5 years ago

I completely fail to see the point of your code snippets. They don't show anything useful.

sorry for the delay in responding
thanks for the comments. I will research the solution and post as soon as I solve it.
Thanks.

I did it. There was really header formatting but it wasn't being passed in the Array. array(self::$jsonA)
Thanks...

public static function reportTrips($sessionId,$deviceId,$from,$to){
    
    $data='deviceId='.$deviceId.'&from='.$from.'&to='.$to;
    
    return self::curl('/api/reports/trips?'.$data,'GET',$sessionId,'',array(self::$jsonA));
}

Dear ... I made my report in PHP using the API.
But I realized that some values are not equal.
On the platform shows one value and the API shows another.
EX: Starts from the API route:> 2020-01-17 12:27:00
Start of the route in the platform report:> 17-01-2020 09:27:00
It is 3 hours apart.
What can it be?