Using js in a node environment with npm request.
I'm trying to grab Id from body.
Body:
[
{
"Id": 201801310058,
"ItemType": 2,
"SourceId": 2,
"SourceUID": "4c45370f-a63d-4768-8772-03a7d7b364ff",
"SourceName": null,
"Duration": 16564,
"Synchronized": false,
"TimeStamp": "2018-01-31T18:01:03.7510329+01:00",
"TrigValue": 0.0,
"DataSize": 24766691,
"Reindexed": false
}
]
Without the square brackets it was easy using body["Id"].
What is the best practice in this case?
Edit:
Here's the whole code:
request('http://localhost:8124/Json/GetLastItems?sourceId=-1&numRecords=1&authToken=f3c6a605-7265-4a4d-922b-dd5c5f9966ee', function (error, response, body) {
console.log(body[0].Id);
});
body[0].Id is undefined