Error when changing user password using API Rest

andsdoug 9 years ago

This is GET output of my users.

GET
http://127.0.0.1:8082/api/users

[
{
"id": 1,
"attributes":{},
"name": "admin",
"email": "admin",
"readonly": false,
"admin": true,
"map": "osm",
"distanceUnit": "km",
"speedUnit": "kmh",
"latitude": -23.615018,
"longitude": -48.420005,
"zoom": 7,
"twelveHourFormat": false,
"password": null
},
{
"id": 28,
"attributes":{},
"name": "old user",
"email": "oldmail@mydomain.com",
"readonly": true,
"admin": false,
"map": "osm",
"distanceUnit": "km",
"speedUnit": "kmh",
"latitude": -15.798272,
"longitude": -50.726411,
"zoom": 4,
"twelveHourFormat": false,
"password": "password"
}

I was sent this rest to change 3 parameters on Id 28

PUT

http://127.0.0.1:8082/api/users/28

{
  "email": "oldmail@mydomain.com",
  "name": "new_user",
  "password": "NEWPASSWORD"
}

this is the new GET output. Traccar server was created a new ID 0. And did not change de parametres of ID 28

http://127.0.0.1:8082/api/users

GET AGAIN 
[
{
"id": 0,
"attributes":{},
"name": "new_user",
"email": "oldmail@mydomain.com",
"readonly": false,
"admin": false,
"map": null,
"distanceUnit": null,
"speedUnit": null,
"latitude": 0,
"longitude": 0,
"zoom": 0,
"twelveHourFormat": false,
"password": "NEWPASSWORD"
},
{
"id": 1,
"attributes":{},
"name": "admin",
"email": "admin",
"readonly": false,
"admin": true,
"map": "osm",
"distanceUnit": "km",
"speedUnit": "kmh",
"latitude": -23.615018,
"longitude": -48.420005,
"zoom": 7,
"twelveHourFormat": false,
"password": null
},

{
"id": 28,
"attributes":{},
"name": "old user",
"email": "oldmail@mydomain.com",
"readonly": false,
"admin": false,
"map": "osm",
"distanceUnit": "km",
"speedUnit": "kmh",
"latitude": -15.798272,
"longitude": -50.726411,
"zoom": 4,
"twelveHourFormat": false,
"password": null
}
]
Anton Tananaev 9 years ago

You need to send full user model (including id) in the PUT JSON request.

Sebastián Hernández 7 years ago

Hey Anton,

I need to update only the password of a single user, given his userId. For doing this, currently I have to fetch all users, find the user object corresponding to that userId and call PUT passing the full user model.

I have two questions:

  1. Are you planning to implement PATCH in the API?
  2. Why the API doesn't allow GET for /users/{id}?
    Any of this two options would make us life a little easier.

As always, thanks for such an amazing system as Traccar.

Anton Tananaev 7 years ago
  1. There is no plan at the moment.
  2. Because there was no need for it in the official app. You are welcome to contribute.