Traccar API 500 Error on getting positions

Obaid Khan7 years ago

I am making a windows forms application for traccar. Everything works fine except fetching history positions.
My request code is

private List<Position> pastPositions(Device d)
        {
            List<Position> positionList = controller.PositionsGet(d.Id, DateTime.Now.AddDays(-2), DateTime.Now, null);
            return positionList;
        }

The following error is returned by the server

org.traccar.Client.ApiException: 'Unexpected character encountered while parsing value: {. Path '[0].network', line 1, position 434.'
Anton Tananaev7 years ago

Make sure that you send Accept header in the request.

Obaid Khan7 years ago

Im using swagger generated c# library. I am using basic auth in Configuration. Where and how should I send Accept header in the request?

Obaid Khan7 years ago

When I use the following code, I get no error

Position p = null;
p = controller.PositionsGet(null, null, null, positionID)[0];

This is strange

Obaid Khan7 years ago

If I pass dates in parameters then I get error.
Looks like the server is not returning more than 1 instance of position.

Anton Tananaev7 years ago

Are you sure date format that you use is correct?

Obaid Khan7 years ago

Library takes DateTime? as a parameter. I see there is no convertion from regular C# TimeDate to UTC8601 format. I will modify the library and give it another try.

Obaid Khan7 years ago

I modified the library and requested the positions with ISO8601 format and still got the same error. The problem is not about the time because when I run loop and request the position by positionID (loop counter), I get nullpointer exception of some other error.

Obaid Khan7 years ago

Now I get this error

NullPointerException (PositionResource:58 < ...)'
Anton Tananaev7 years ago

Make sure you send Accept header in the request.

Obaid Khan7 years ago

I send Accept header. If I do not pass any parameter then the latest location of all devices is returned fine. But if I pass time then error occures.
Now the error is

'Unexpected character encountered while parsing value: {. Path '[3].network', line 1, position 1963.'

when I used this code

Position p = controller.PositionsGet(null, DateTime.Now.AddDays(-2), DateTime.Now)[0];
Obaid Khan7 years ago

I wonder why latest instance of position for every device is returned and not the past position instances. I have been searching for solution the whole day today.

Anton Tananaev7 years ago

I'm a bit tired of going in circles. Please provide full request and response that you send. I'm not interested in C# code. I just want to see HTTP request.

Obaid Khan7 years ago

How can I get the raw json response of the server from swagger library?

Obaid Khan7 years ago

I am using the swagger generated c# library solution. It wont show me the http request. I can only use the functions that the library provided me. I am uploading the whole solution to my github.