Positions/trips from the API

Fernando Encina4 years ago

Hi Anton, i have a question about the Traccar API, i have a device configured, but when i get the information from the API, passing (from, to, deviceId) parameters, i have responses from future times (i.e, i am currently at 13:00 pm and i get location from 16:05:00 PM (i think is a record from yesterday) but i set in the parameters the time correctly (i think). here a testing from Postman and the result that i get in the app.

App

Postman

when i see the database directly and all seems be correctly.

Database

also i see the server time and is ok.

server

when i see the report from the traccar web, is also ok.

Traccar Web

i only have this problema by getting the information from the API, is there something that i am doing wrong? or is there any param that i have to configure in the traccar.xml for the timezone or something like that?

Anton Tananaev4 years ago

Traccar web app uses the same API. Compare your requests with what official web app sends.

Fernando Encina4 years ago

thanks for your quick response, can you please tell me in wich file can i see that?.I have try to understand the code, but i don't have any experience in javascript, so is hard to me to find the example. Or if you can show me an example of the code where is this sends, i will be very grateful. My request sends this.
http://myserver/api/reports/trips?from=2020-08-03T00:01:00Z&to=2020-08-03T23:59:00Z&deviceId=1 (here i try to cover the entire day)
I can get all the informations type that i need (Stops, Devices,Commands, Trips, etc) i just have problem with this case, is anything bad in the DateTime format? i see the documentation and i think the format is correct (in IS0 8601),thanks.

Anton Tananaev4 years ago

You don't need to understand the code. Just use browser developer console to see the requests.

Fernando Encina4 years ago

Great tip, this will be very useful to me, but sadly i have the same result, this is what i see in the console, but wich is exactly the same that i get in my app and from postman testing the response.
This is what i see in the console.
Console
and as you can see doesn't match with the data displayed in the web report (i select the "today" range for the report).
Web_report.

Anton Tananaev4 years ago

I'm confused. Have you adjusted for the timezone?

Fernando Encina4 years ago

i don't, do yo mean under server settings?, i just have two attributes set, one for speed and for distance, i dont had to because in the web app it shows the time correctly, just when i want to use the result of the API externaly i have the problem, is there a place where i have to set the timezone? (in the device that is sending the information i have the correct timezone, as you can see in the database the data is correct, i also verify with the sms command) i am also very confused..
Server_settings.

Anton Tananaev4 years ago

What is the time value you get and what is the time you expect? Please provide one example and include timezones.

Fernando Encina4 years ago

I appreciate your interest. This image shows the value that i get from the API, and as you can see the data displayed in the web report (wich is what i want to replicate in my app, because is the correct) are not the same data that i can see in the response, is there any "trick" in the web app for that? maybe substracting some hours depends of the current timezone? (by the way, my timezone is (GMT-4), if is that your question) or is an param/attribute that is in the server settings or in traccar.xml?

Anton Tananaev4 years ago

Web app obviously displays the time in your local timezone. Everything seems to match. Not sure what you think is incorrect.

Fernando Encina4 years ago

I really appreciate your interest, thanks anyway for your effort and time.

Abel4 years ago

Hi Fernando,

There's any way I can contact you to discuss about the subject?

Regards.

Anton Tananaev4 years ago

Just a warning. Please don't share personal contact details on the forum. If you want to discuss something, discuss it here.

Fernando Encina4 years ago

Hi Abel, Sure! what can i help you with? in case that you have the same problem, and complementing to Anton, to get the correct date (in my timezone) i had to subtract the hours of the result that i get from the API, i.e. If the API returns "2020-08-07T18:03:03.000+0000" (the correct Hour for me would be 14:03:03...) so i had to substract 4 hours. I dont know if there any best solution but for me works for now.