[Solved] Associate a device with a user  

  RSS

JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 2 months ago
Posts: 27
23/03/2019 1:46 pm  

Hello,

I would like to know if you have plans to improve a new feature on this very good solution to be able to associate  an "existing devices" <=> "user".


Quote
jaimzj
(@jaimzj)
Guru Admin
Joined: 11 months ago
Posts: 46
23/03/2019 1:55 pm  

The feature you are referring to is already implemented.

Markers & maps are magical !!!


ReplyQuote
JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 2 months ago
Posts: 27
24/03/2019 3:20 am  

you are right, thank you.
I am testing the code below and works well, unless for one inconvenient: if I try associate the same device with the same user, how I can avoid duplication on table tc_user_device:

 

$userId = "12";
$deviceId="2";

$c = gps::assignUserDevice($sessionId,$userId,$deviceId);
$response_3 = $c->response;
$responseCode_3 = $c->responseCode;
if($responseCode_3 == '204'){
echo "Usuario e devices associados com sucesso";
}
else{
//echo "Nao foi possivel associar usuario com este device <br><br>";
echo "Codigo erro: " . $responseCode_3 . "<br><br>";
echo "Descricao erro: " . $response_3 . "<br><br>";

}

regards

This post was modified 2 months ago 2 times by jaimzj

ReplyQuote
jaimzj
(@jaimzj)
Guru Admin
Joined: 11 months ago
Posts: 46
24/03/2019 3:28 am  

Duplication is something that we cant control until its done on Traccar end.

However you can always call other API's to figure out if the user has that device under his records already.

Or as an alternative you can also maintain a separate database table for this purpose and write a small function to check and update this table.

Markers & maps are magical !!!


ReplyQuote
JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 2 months ago
Posts: 27
24/03/2019 3:32 pm  

understood. Thank you!


ReplyQuote
anon7
(@anon7)
New Member
Joined: 2 months ago
Posts: 1
30/03/2019 7:32 am  

hello mr. james I get a problem, and like this.

Notice: Undefined variable: data in /Applications/XAMPP/xamppfiles/htdocs/www/tracking/test/traccarApi.php on line 17

Notice: Undefined variable: sessionId in /Applications/XAMPP/xamppfiles/htdocs/www/tracking/test/traccarApi.php on line 17
{"id":1,"attributes":{},"registration":true,"readonly":false,"map":"","bingKey":"","mapUrl":"","distanceUnit":"","speedUnit":"","latitude":0.0,"longitude":0.0,"zoom":0,"twelveHourFormat":false,"forceSettings":false,"coordinateFormat":"","version":"3.9-SNAPSHOT"}200


ReplyQuote
jaimzj
(@jaimzj)
Guru Admin
Joined: 11 months ago
Posts: 46
30/03/2019 1:38 pm  

@anon7  you should create a new topic instead of adding your question to existing topics.

The api response you shared has nothing to do with associating a device with a user.

 

As for the response and PHP notices you shared, I do not see any problem in it.

Create a new topic and explain your problem with precise details.

Markers & maps are magical !!!


ReplyQuote
Share:
  
Working

Please Login or Register