Error in creating user through API

webtechanand8 years ago

Hi I am using traccar 3.7

I tried to create user through API by sending post request at /api/users

But i am getting error

(
    [message] => Column 'hashedpassword' cannot be null
    [details] => Column 'hashedpassword' cannot be null - MySQLIntegrityConstraintViolationException (... < QueryBuilder:443 < DataManager:170 < PermissionsManager:197 < ...)
)

My Post data is

{
  "id":0,
  "name":"user_1",
  "email":"user_1",
  "readonly":0,
  "admin":0,
  "map":"osm",
  "language":"en",
  "distanceUnit":"km",
  "speedUnit":"kmh",
  "latitude":0,
  "longitude":0,
  "zoom":0,
  "password":"abcd1234",
  "twelveHourFormat":0
}

As per swagger documentation there is no hashPassword field for api, so i thought that it will be created by traccar itself using plain password provided through 'passowrd' field in post.

I also tried by putting hashedpassword field in curl's post data but no luck.

Can you please help me in this.

Anton Tananaev8 years ago

Try to send less parameters:

{
  name: "user_1",
  email: "user_1",
  password: "abcd1234"
}

Password hash should be calculated automatically. Not sure why it doesn't happen.

webtechanand8 years ago

Still same result..

Anton Tananaev8 years ago

Try to register user through web interface and see if it work. You can also check browser console to compare the API request with yours.

webtechanand8 years ago

I found the issue. It was a silly mistake by me. I was passing the wrong array to curl post.
Thanks for suggestion to check browser console to compare api request. It will help me out in further implementations in my application

Howard6 years ago

I used this formatted json and it works
{
"name": "user_1",
"email": "user_1",
"password": "abcd1234"
}