Good afternoon.
I am trying to perform tests with the Traccar API using the command line program cURL, but I am unable to authenticate with my username and password through it.
According to the documentation,
There are two authorization options:
Using session cookies (see "session" URL path)
Standard HTTP authorization header
Trying to send an authorization header like this:
C:\curl-7.68.0-win64-mingw\bin>curl -H "Authorization: Basic [my username]:[my password]" http://localhost:8082
returns the following:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Traccar</title>
<link rel="icon" sizes="192x192" href="/icon.png">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="stylesheet" href="app.css">
</head>
<body>
<div id="spinner"></div>
<div id="attribution">Powered by <a href="https://www.traccar.org/">Traccar GPS Tracking System</a></div>
<script id="loadScript" src="load.js"></script>
</body>
</html>
Then I try to make a request like this:
C:\curl-7.68.0-win64-mingw\bin>curl -X GET http://localhost:8082/api/devices
which results in:
HTTP 401 Unauthorized - WebApplicationException (SecurityRequestFilter:113 < ...)
So it's not authenticating me the first time.
Trying to make a GET request for http://localhost:8082/api/session returns:
HTTP 404 Not Found - WebApplicationException (SessionResource:96 < ...)
All of this happens with http://demo.traccar.org/api/ too.
Thank you in advance for your help.
Domingo Hernández
What you are doing doesn't really make any sense to me. If you want to use authorization header, you have to send it with your API request. If you want to create a session, you have to use POST request.
I would recommend you to look at how official web app use the API.
hola Anton consultarte donde se puede ver, cómo la aplicación web oficial hace uso de la API. Gracias por tu apoyo
Hello Anton, ask where you can see how the official web application uses the API. Thanks for your support
Browser developer console. I'm surprised that so many people are unaware of it.
Good afternoon.
I am trying to perform tests with the Traccar API using the command line program cURL, but I am unable to authenticate with my username and password through it.
According to the documentation,
Trying to send an authorization header like this:
returns the following:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title>Traccar</title> <link rel="icon" sizes="192x192" href="/icon.png"> <link rel="apple-touch-icon" href="/apple-touch-icon.png"> <link rel="stylesheet" href="app.css"> </head> <body> <div id="spinner"></div> <div id="attribution">Powered by <a href="https://www.traccar.org/">Traccar GPS Tracking System</a></div> <script id="loadScript" src="load.js"></script> </body> </html>
Then I try to make a request like this:
which results in:
So it's not authenticating me the first time.
Trying to make a GET request for http://localhost:8082/api/session returns:
All of this happens with http://demo.traccar.org/api/ too.
Thank you in advance for your help.
Domingo Hernández