You should get a cookie session in the header.
I am sending Cookie in the header.
Response Header:
Date: Thu, 18 Mar 2021 07:03:59 GMT
Content-Type: application/json
access-control-allow-headers: origin, content-type, accept, authorization
access-control-allow-credentials: true
access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS
access-control-allow-origin: *
Content-Length: 401
Server: Jetty(9.4.36.v20210114)
Response Body
Can anyone help me to integrate this traccar. I am not able to get token and without token cannot proceed. please
What token and why do you need it?
$adminLoginResponse = gps::loginAdmin();
$sessionId = gps::$cookie;
$_SESSION['sessionId'] = $sessionId;
//dd($sessionId);
$tokenResponse = gps::session($sessionId);
$response = $tokenResponse->response;
$token = json_decode($response);
$token_traccar = $token->token;
$test = gps::login(env('USR_TRACCAR'),env('PWD_TRACCAR'));
$token = json_decode($test->response);
$tc_token = $token->token;
in login function curl is being called and the curl i have posted above and the response also.
return self::curl('/api/session','POST','JSESSIONID=node0spbxks097p05bxx5mupjqry13638.node0',$data,array(self::$urlEncoded));
Great conversation.
What am i doing wrong here sir.
Probably everything if you cannot even explain what you are trying to achieve.
I am trying to login first thing and get session id so i can communicate with the api easily.
later i will trying to get gps locations of the devices.
And how do you plan to use that token exactly?
$adminLoginResponse = gps::loginAdmin();
$sessionId = gps::$cookie;
$_SESSION['sessionId'] = $sessionId;
//dd($sessionId);
$tokenResponse = gps::session($sessionId);
$response = $tokenResponse->response;
$token = json_decode($response);
$token_traccar = $token->token;
$test = gps::login(env('USR_TRACCAR'),env('PWD_TRACCAR'));
$token = json_decode($test->response);
$tc_token = $token->token;
$groupsResponse = gps::groups($sessionId);
$response3 = $groupsResponse->response;
$groupes = json_decode($response3);
$positionsResponse = gps::positions($sessionId);
$response4 = $positionsResponse->response;
$positions = json_decode($response4);
$devicesResponse = gps::devices($sessionId, '');
$response2 = $devicesResponse->response;
$devices = json_decode($response2);
$geofencesResponse = gps::geofences($sessionId);
$response5 = $geofencesResponse->response;
$geofences = json_decode($response5);
<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'http://135.125.140.197:8082/api/session', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => 'email=j.vana%40ris******.com&password=R!%40****%252***', CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded', 'Cookie: JSESSIONID=node0spbxks097p05bxx5mupjqry13638.node0' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
for this code i am getting response
{ "id": 1, "attributes": {}, "name": "Ri******", "login": "", "email": "j.vana@ri******.com", "phone": "", "readonly": false, "administrator": true, "map": "carto", "latitude": 0.0, "longitude": 0.0, "zoom": 2, "twelveHourFormat": true, "coordinateFormat": "dms", "disabled": false, "expirationTime": null, "deviceLimit": -1, "userLimit": 0, "deviceReadonly": false, "token": null, "limitCommands": false, "poiLayer": "", "password": null }
How can i get token for further apis and etc.