Generating User token traccar ver 5.8

p7rck 3 years ago

Hi, I'm new to Traccar. I am building an erp that has fleet management. I have setup my Traccar server already and want to use API, to fetch my devices for my server. The API uses token for authorization. I tried to generate one using the POST request in api/session with user credentials. I got a 200 response but token is not there. Is there someone who can guide me on how to generate the user tokens using api? Thank you in advance

Anton Tananaev 3 years ago

Have you checked how the official app generates the token?

p7rck 3 years ago

I haven't, where can I checked? Can you guide me through this?

Anton Tananaev 3 years ago

The easiest option to check is the browser network console. Request a token and check the API request in the console.

p7rck 3 years ago

Thank you for your response
How do you request a token?
i am using api/session
this is what i get as a response

{
    "id": 3,
    "attributes": {},
    "name": "John Doe",
    "login": null,
    "email": "mail@mail.com",
    "phone": null,
    "readonly": false,
    "administrator": true,
    "map": null,
    "latitude": 0.0,
    "longitude": 0.0,
    "zoom": 0,
    "twelveHourFormat": true,
    "coordinateFormat": null,
    "disabled": false,
    "expirationTime": null,
    "deviceLimit": -1,
    "userLimit": 0,
    "deviceReadonly": false,
    "limitCommands": false,
    "disableReports": false,
    "fixedEmail": false,
    "poiLayer": null,
    "password": null
}

and what does login mean?

p7rck 3 years ago

I remember last year when I learned about traccar token was included in api/session response

p7rck 3 years ago

Can someone help me with this?

Javier Marcos 2 years ago

Although this question has already been answered previously, I will provide my own response, giving instructions to test it using Postman.

  • HTTP Method: POST
  • URL: http://my-server-traccar/api/session/token
  • Auth: Basic Auth (Fill in username and password)
  • Body: Select x-www-form-urlencoded
    • Key: expiration
    • Value: date and time in ISO format (Example: 2024-02-28T15:30:00Z)

Reference: https://www.traccar.org/forums/topic/user-tokens-in-v-53/#post-75007