API/Positions multiple device id's

Morten2 months ago

Is it possible to get alle positions in between two points in time from multiple devices with one call?

I know I can call api/positions wihtout a device id to get the last position of all devices. But I need all locations within a timeframe, so that wont work.

I also know that I can call api/positions?deviceId=1&from=2024-09-25T00:00:00Z&to=2024-09-25T23:59:00Z to get all positions of that id within the timeframe. And as such I can just call that endpoint multiple times with different deviceID, but my code would be faster (i think) if it don't need to iterate over an array of id's and call the url several times. But I'm unsure if such an endpoint does exists, it does not seem to be the case from what I've read in the API documentation.

Anton Tananaev2 months ago

You can pass multiple device IDs.

Morten2 months ago

Fantastic! How do I do that? deviceId=1&deviceId=2 does not work at least :)

Anton Tananaev2 months ago

It works for me exactly like that.

Anton Tananaev2 months ago

Actually wait. Try using route report endpoint instead. It returns the same thing.

Morten2 months ago

The reports works like that, but it returns the data in a speadsheet not JSON format. I can't get the api/positions?deviceId=1&deviceId=2&from=2024-09-26T00:00:00Z&to=2024-09-27T23:59:00Z to return other than data from deviceId1 (or more precisely the first parameter whichever it might be).

Can the reports endpoint return the data in JSON?

Anton Tananaev2 months ago

Reports can definitely report JSON. You just need to tell it that you want JSON. Provide the correct Accept header value.

Morten2 months ago

Great - can you point me to where I can learn about how to do that then?

Anton Tananaev2 months ago

That's HTTP protocol standard. It's not something specific to Traccar. I'm sure you can easily Google it.