unable to add device thru traccar php api, need help

jerry licayan4 years ago
<?php
include('traccarApi.php');
$email = 'arvid1234';
$password = 'arvid123';
$name = 'arvid123';
$attributes = '{}';
$sessionId='-1';
$uniqueId='2345';
$phone='09094126387';
$model='NA';
$category='NA';
$a = gps::deviceAdd($sessionId,$name,$uniqueId,$phone,$model,$category,$attributes);
$response = $a->response;
$responseCode = $a->responseCode;
if($responseCode == '200'){
    echo ('true');
}else{
    echo 'Invalid Data Try Again';
}
?>

public static function deviceAdd($sessionId,$name,$uniqueId,$phone,$model,$category,$attributes){
    $id = '-1';
    $sessionId=$sessionId;
    $attributes = $attributes;
    $name=$name;
    $uniqueId=$uniqueId;
    $phone=$phone;
    $model=$model;
    $category=$category;
    $data='{"id":"'.$id.'","name":"'.$name.'","uniqueId":"'.$uniqueId.'","phone":"'.$phone.'","model":"'.$model.'","category":"'.$category.'","attributes":'.$attributes.'}';
    return self::curl('/api/devices','POST',$sessionId,$data,array(self::$jsonC));
}
Anton Tananaev4 years ago
  1. Have you created a session?
  2. What is the error message?
jerry licayan4 years ago

Hi anton,

I really dont know what or how to create a session, by the way here is the error message when executing the above code

HTTP 401 Unauthorized - WebApplicationException (SecurityRequestFilter:113 < ...)401
Anton Tananaev4 years ago

Please read the documentation:

https://www.traccar.org/traccar-api/

Elias Castillo4 years ago

Hi! i have te same problem, i can't create a "session" via traccarApi.php :/ help, I have read the documentation, but it does not indicate how to start it