Hello,
I will collect data via API for our project. I would like to get the readValue of each device but I couldn't find the way to get it. Because I am very new at javascript and API environment.
The Data API format is shown below. In order to get data, I have tried 2 different methods:
Method 1:
I have added HTTP retriever datasource and added a point. Then I get an error.
Is there any suggestion, what is the best way/datasource to get this data?
How do we enter authorization info (basic, bearer etc.) to http datasources?
HTTP retriever url: http://10.35.173.145:84/api/Lin
Point Value RegEx: .readValue":(\d+).(?=."deviceName":"PDU-24A-42F11".).
Error: Invalid response from "http://10.35.173.145:84/api/Lin": 401
//url: http://10.35.173.145:84/api/Lin
// Bearer Auth code: eyJhbGciOiJIUzI1NiIsInR5
{
"lastUpdate": "2020-06-10T10:52:39.8352606+03:00",
"result": [
{
"deviceId": 27,
"deviceName": "PDU-24A-42F11",
"room": "DC_KAR",
"row": "M_KAR",
"location": "SOL",
"tagId": 20987,
"tagName": "Voltage",
"unit": "V",
"readDate": "2020-06-10T10:51:45",
"readValue": 228.87
},
{
"deviceId": 33,
"deviceName": "PDU-23B-7F1",
"room": "DC_KAR",
"row": "M_KAR",
"location": "SOL",
"tagId": 21155,
"tagName": "Voltage",
"unit": "V",
"readDate": "2020-06-10T10:52:23",
"readValue": 228.97
},
{
"deviceId": 34,
"deviceName": "PDU-23B-29F11",
"room": "DC_KAR",
"row": "M_KAR",
"location": "SOL",
"tagId": 21183,
"tagName": "Voltage",
"unit": "V",
"readDate": "2020-06-10T10:51:31",
"readValue": 228.97
},
{
"deviceId": 35,
"deviceName": "PDU-23B-25F11",
"room": "DC_KAR",
"row": "M_KAR",
"location": "SOL",
"tagId": 21211,
"tagName": "Voltage",
"unit": "V",
"readDate": "2020-06-10T10:51:00",
"readValue": 228.87
},
{
"deviceId": 42,
"deviceName": "PDU-23B-33F11",
"room": "DC_KAR",
"row": "M_KAR",
"location": "SOL",
"tagId": 21327,
"tagName": "Voltage",
"unit": "V",
"readDate": "2020-06-10T10:51:34",
"readValue": 228.97
},
{
"deviceId": 30,
"deviceName": "PDU-23B-38F11",
"room": "DC_KAR",
"row": "M_KAR",
"location": "SOL",
"tagId": 21071,
"tagName": "Voltage",
"unit": "V",
"readDate": "2020-06-10T10:52:30",
"readValue": 228.89999
}
}
Method 2:
I have added a global script shown below. When I print the content, I see the data. But I cannot get the read value of device. How can I get it?
function linye(message) {
HttpBuilder.request({
path: "http://10.35.173.145:84/api/Lin",
method: "GET",
headers: {
ContentType : "application/json",
Authorization : "Bearer eyJhbGciOiJIUzI1NiIsInR5",
},
err: function(status, headers, content) { //errorCallback for linguistic completion
throw "Request got bad response: " + status+content;
},
resp: function(status, headers, content) { //responseCallback
return true; //will print in wrapping print()
},
excp: function(exception) { //exceptionCallback
throw exception.getMessage();
}
})
}
Thanks in advance!