Como usar a api PHP

Olá pessoal!!

Encontrei o código abaixo em .php mas não estou sabendo como chamar a função addUser. Tentei o seguinte mas não deu certo:

//chamando a função:
gps.userAdd('','Teste', 'teste@teste', '123456', '') ; // isso não está funcionando

class gps {

public static $host='http://meudominio:8082';
private static $adminEmail='admin';
private static $adminPassword='minhasenha';
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';



//users
public static function userAdd($sessionId,$name,$email,$password,$attributes){
    
    $id = '-1';
    $name = $name;
    $email = $email;
    $password = $password;
    $readOnly = 'false';
    $administrator = 'false';
    $map = '';
    $latitude = '0';
    $longitude = '0';
    $zoom = '0';
    $twelveHourFormat = 'false';
    $coordinateFormat = '0';
    $disabled = 'false';
    $expirationTime = '';
    $deviceLimit = '-1';
    $userLimit = '-1';
    $deviceReadonly = 'false';
    $limitCommands = 'false';
    $token = '';
    $attributes = $attributes;

    $data='{"id":"'.$id.'","name":"'.$name.'","email":"'.$email.'","readonly":"'.$readOnly.'","administrator":"'.$administrator.'","map":"'.$map.'","latitude":"'.$latitude.'","longitude":"'.$longitude.'","zoom":"'.$zoom.'","password":"'.$password.'","twelveHourFormat":"'.$twelveHourFormat.'","coordinateFormat":"'.$coordinateFormat.'","disabled":"'.$disabled.'","expirationTime":"'.$expirationTime.'","deviceLimit":"'.$deviceLimit.'","userLimit":"'.$userLimit.'","deviceReadonly":"'.$deviceReadonly.'","limitCommands":"'.$limitCommands.'","token":"'.$token.'","attributes":'.$attributes.'}';

    return self::curl('/api/users','POST',$sessionId,$data,array(self::$jsonC));
}

(...)

}

Podem me ajudar??

Jose B6 years ago

Hello!!!

I'm still trying. Where it does not ask for this '$sessionId', I already have.
See:

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

include('traccarApi.php');

$a = gps::server();
echo $response = $a->response;
echo $responseCode = $a->responseCode;

?>

I'm trying to get answers from where I get this variable here:
https://www.traccar.org/forums/topic/error-api-traccar/#post-41705

I got it with the tips of:
https://www.traccar.org/forums/topic/error-api-traccar/#post-41705

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

include('traccarApi.php');

$a = gps::loginAdmin();

if($a->responseCode=='200') {
    $sessionId = gps :: $cookie;
    $c = gps::userAdd($sessionId,'Teste Nome','teste','teste','{}');
    echo $response = $c->response;
    echo $responseCode = $c->responseCode;
    
}else{
 echo 'Incorrect email address or password';
}