Api Positions not working

Gantz7 years ago

Hi, im new using the traccar api and i have a problem
i have a local traccar server running in my pc it tracks fine via the web client, but when i try to enter to
http://localhost:8082/api/positions/ it shows an error saying "ERR_INVALID_RESPONSE"

yet i try that direction in the demo of traccar and it works.

help what im doing wrong

Anton Tananaev7 years ago

You have to include "Accept" header in the request.

Gantz7 years ago
<script type="text/javascript">
                var name = "admin";
                var uid = "admin";
                $.ajax({
                    type: 'get',
                    url: 'http://localhost:8082/api/positions/',
                    headers: {
                        "Authorization": "Basic " + btoa("username" + ":" + "password")
                    },
                    contentType: "application/json",
                    data: JSON.stringify({
                        name: name,
                        uniqueId: uid
                    }),
                    success: function (response) {
                        console.log(response);
                    }
                });
            </script>

this is my request

Anton Tananaev7 years ago

I don't see any "Accept" header in your request. Please read my previous comment.

Gantz7 years ago

Im kind of new in these types of request. could you give me an example of a correct request please? it will be much apreciated!! thx!!

Malkit Singh7 years ago
Gantz7 years ago

yeah thanks it worked, but now it shows the following error:

HTTP 401 Unauthorized - WebApplicationException (SecurityRequestFilter:103 < ...)

sorry for the trouble and thanks in advance.

Anton Tananaev7 years ago

I think the error message is pretty self-explanatory. You are not authorized. You have to either have a logged-in session cookie, or use basic authorization header.

german sanchez 4 years ago
HTTP 401 Unauthorized - WebApplicationException (SecurityRequestFilter: 108 < ...)
Dariusz3 years ago

I have found a much easier way to pass it:

http[s]://user:password@traccar .com/api/positions

it works :)