Help with API access needed.

JMTM8 years ago

[node.js code]


var request = require('request');
//get all Ids

var getPosition = request.get('xxxxxxxx.com:8082/api/positions',{
    'auth': {
    'user': 'xxxx',
    'pass': 'xxxx',
    'sendImmediately': true},
    'params': {
    }
  });

function callback(error, response, body) {
  console.log("MyResult " + response.statusCode)
  if (!error && response.statusCode == 200) {
    var info = JSON.parse(body);
    console.log (info);
  }
}

request (getPosition, callback);

Hi. With the above code I'm trying to get some data from traccar using Node.js. I would like to get

A) all coordinates for a specific device between dates
B) Latest for all devices.

The above code, gives-me the latest for all devices, however it only works 50% of the time. The others it fails with a 200 in response, but nothing arrives in the body so we get a Json Error, wich is weird, but that's what I'm getting.

Also the deviceId in the reply has nothing to do with the device ID I inserted in the "portal" so I never know to which device the results belong.

Help would be welcomed.

Many thanks.

Anton Tananaev8 years ago

A) You have to provide deviceId and dates.
B) Without parameters will give you latest for all devices.

It won't fail with 200 status code. I think you need to double-check everything. If there is an error, you should get a proper status code and error details in the body.

To map device ids to unique ids, you would have to get a list of devices via API as well.