Ok interesting is, when I restart via “node server.js” than I get the latest data. So there is some caching on the node server or on the auth script of the Orchestrator node package.
The problem is that the res.send is put outside of the callback. So it never waits for the actual finish of the REST api call.
This is the base code where it just took the static result of the first request, it never updated the results:
app.get('/robots', function (req, res) {
...
var orchestrator = require('./authenticate');
var results = {};
var apiQuery= {};
orchestrator.get('/odata/Robots', apiQuery, function (err, data) {
for (row in data) {
results[i] =
{
'id' : row.id,
...
};
}
});
return res.send({results});
});
The solution is to moving the res.send({results});into the orchestrator.get, then it properly overwrites the results as it waits correctly for the callback:
app.get('/robots', function (req, res) {
...
var orchestrator = require('./authenticate');
var results = {};
var apiQuery= {};
orchestrator.get('/odata/Robots', apiQuery, function (err, data) {
for (row in data) {
results[i] =
{
'id' : row.id,
...
};
}
return res.send({results});
});
});