How to create devices for other users via API?

Miroa year ago

Hello everybody!
What would be the way to create devices for other Traccar users via API?
I'm using an application made in Delphi to create devices. But I can only create it if I am logged in on behalf of the target user.
This is not always possible, as the user can change their password..

Anton Tananaeva year ago
Miroa year ago
Miroa year ago

Anton, I know how bad it is to hear other people's problems, but I wouldn't be here if I had understood the API documentation.
No matter how much I read and re-read it, the negative result is always the same... I know I must be doing something wrong.

The only way I was able to do this was by accessing the tc_user_device table (via mySQL) and changing the "deviceid" field. But this way is not functional, as you need to reload the web page for the device to be displayed.

  • The strange thing is that I can execute all the API commands successfully, I just can't assign the device to another user.

  • 1 I log in with user admin on the API = OK

  • 2 I create the device in my user = Ok

But I can't assign it to another user, see below:
Loged with Admin

URL
http://XXX.251.222.19:8082/api/permissions

Metod : POST

Data:

{"userId":27,"deviceId":237,"groupId":0,"geofenceId":0,"notificationId":0,"calendarId":0,"attributeId":0,"driverId":0,"managedUserId":0,"commandId":0}

Response:
EIdHTTPProtocolException
Message error: HTTP/1.1 400 Bad Request

Can you see where I'm going wrong?

{}'s Miro (Brazil)

PS.
Headrs:

 Request.ContentType := 'application/json';
 Request.Accept := 'application/json';
 Request.BasicAuthentication := True;
 Request.Username := edUser;
 Request.Password := edPassword;
Anton Tananaeva year ago

The data should be (only include what's needed):

{"userId":27,"deviceId":237}
Miroa year ago

So it worked!!!

But partially working. It still depends on a reload of the web page to be shown.

  • 1 If I am logged in as an Admin user, when creating the device and updating it, it is loaded in the menu automatically.
  • 2 When I transfer to another user, even though he is logged in and viewing the web page, the device is not shown, only after reloading the page.
  • 3 If I delete the device in the Admin user, it is also deleted in the target user.

Is this behavior normal?

Anton Tananaeva year ago

Yes, that's expected.

Miroa year ago

Creating a Device via API with immediate visualization, without reloading the web page.

Traccar version 5.9
It's a paleative solution, but it solved my pain!

  • 1 My system (HTTP in Delphi) logs in with my "User Admin".
  • 2 I select the target user from the "tc_users" table (via mySQL).
  • 3 I change this user to an Admin ("administrator = True").
  • 4 I create a Device, via API, logging in with this user (he is logged in to traccar-web and viewing the web page).
  • 5 I remove this user's privilege ("administrator = False", via mySQL).

... And, that's all!

Miro (Brazil).