Are you sending Accept
header? This has been discussed countless number of times.
The accept header is "*/*", both on /api/devices which return json and on /api/positions, which appearently returns csv.
Ok; I added the Accept: application/json, and now I get json, if I specify a device and times.
{
"id": 1554044,
"attributes": {
"signal": "F",
"distance": 6058426.02,
"totalDistance": 3.058247092E8,
"motion": true
},
"deviceId": 4,
"type": null,
"protocol": "xexun",
"serverTime": "2020-08-31T01:01:49.000+0000",
"deviceTime": "2020-08-31T01:01:45.000+0000",
"fixTime": "2020-08-31T01:01:45.000+0000",
"outdated": false,
"valid": true,
"latitude": 60.069095,
"longitude": -112.08195666666667,
"altitude": 0.0,
"speed": 104.89,
"course": 276.65,
"address": "Northwest Territories, CA",
"accuracy": 0.0,
"network": null
}
]
My Landcruiser is at the mecanics workshop, but in Denmark, not Canada. I guess I need a new tracker.
Adding the Accept-header might have been discussed before, but the API docs just say json is the default.
And it is not logical that the position need the Accept, but the two other endpoints doesn't
The raw /api/positions now also returns json if I add the Accept-header
Please point to the API doc. It might need to be updated.
What do you know....
The /api/positions doesn't have a default content-type.
The /api/reports doesn't have a default content-type.
The rest have "Uses default content-types: application/json"
Also the header say
traccar
Base URL: /api, Version: 4.10
Default request content-types: application/json
Default response content-types: application/json
Schemes: http
It is not very obvious that only these two endpoints require an Accept-header.
Feel free to update the doc.
It is strange, because I don't have a direct way of setting the Accept-header from node-red, and it used to work.
And now it works again, without the accept-header, both from node-red and from Postman test suite.
I don't like things being dependent of the phase of the moon or uninitialized items in memory...
If you don't want undefined behavior you have to provide Accept
header.
Okay... I don't see where update the docs.
But how about "Warning: Unlike the 54 other api-calls, this doesn't have a default value for the output format. If an Accept-header is not provided, the call may randomly fail or work"
Or better yet: Make these calls behave like all the others and as the api-header say; return json unless otherwise requested.
And before this turns into a shout and shit-throwing contest: I should have gone to bed hours ago. Good night, whenever that's appropriate for you.
Make these calls behave like all the others and as the api-header say; return json unless otherwise requested.
I with it was possible, but unfortunately it's not. That would be my preference as well.
You can update API documentation here:
I use postman to test the api, but usually I use node-red
I have just pulled the latest docker image, does no change.
I used to have this return positions:
http://traccar:8082/api/positions
But this now returns
NullPointerException (... < DateUtil:63 < PositionResource:80 < ...)
This should return this: "Without any params, it returns a list of last known positions for all the user's Devices."
If I call
http://traccar:8082/api/positions?from={{fromdate}}&to={{todate}}
( where the dates are javascript .toISOString() )I only get
accuracy;address;altitude;course;deviceId;deviceTime;fixTime;id;latitude;longitude;network;outdated;protocol;serverTime;speed;type;valid;attributes;
/api/devices
and/api/geofences
work as expected; sends json