Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.
HttpBuilder.request()
-
Hi all,
This is my first attempt to make a REST call to retrieve a point values array via Mango scripting source.
Via Swagger:
url:
http://localhost:8080/rest/v2/point-values/multiple-arrays/latest/DP_422050,CDP_614346?limit=3&useCache=NONEresult:
{ "DP_422050": [ { "timestamp": 1567738483443, "value": 175.51602162739323 }, { "timestamp": 1567738423443, "value": 175.16915149128016 }, { "timestamp": 1567738363443, "value": 174.31921651479684 } ], "DP_614346": [ { "timestamp": 1567738483443, "value": 211795 }, { "timestamp": 1567738423443, "value": 211790 }, { "timestamp": 1567738363443, "value": 211785 } ] }
Via Mango scripting data source:
print(HttpBuilder.request({ path: "http://localhost:8080/rest/v2/point-values/multiple-arrays/latest/DP_422050,DP_614346", method: "GET", headers : { "Cookie": "XSRF-TOKEN=6ac16488-db6d-4e64-8353-2faea1433e0f", "X-XSRF-TOKEN": "6ac16488-db6d-4e64-8353-2faea1433e0f", "Content-Type":"application/json;charset=UTF-8", "Host": "localhost:8080", "Accept": "application/json, text/plain" }, parameters: { "limit" : 3, "useCache" : "None", }, //content: "GETs don't have content!", err: function(status, headers, content) { //errorCallback for linguistic completion throw "Request got bad response: " + status; }, resp: function(status, headers, content) { //responseCallback //try to retrieve the HttpBuilder object but no success //var result = JSON.parse(headers); //print(result); print(content); return true; //will print in wrapping print() }, excp: function(exception) { //exceptionCallback throw exception.getMessage(); } }));
result:
nullI also tried to retrieve the headers for a check test but no success. After some thought, I realize this might due to the "GETs don't have content". If this is the situation, how then can I access the point values array from return HttpBuilder object?
Likelihood I am unable to grasp the concept of HttpBuilder correctly and hopefully someone can help me out on the silly mistake I may have overlooked.
Thanks and Best Regards
-
Hi Desmond,
It seems the first issue is a class cast exception for the
excp
function. You can remove this function and theerr
function will be used instead with status code -1. Thanks for bringing this to our attention! https://github.com/infiniteautomation/ma-core-public/issues/1489After that, I also had to modify the
"useCache": "None"
to be"useCache": "NONE"
(other options areCACHE_ONLY
andBOTH
)and I used an authorization token in my testing. This worked for me:var token = "token value from users page" print(HttpBuilder.request({ path: "http://localhost:8080/rest/v2/point-values/multiple-arrays/latest/DP_755013cd-03e3-4e9b-aad1-7a4575e58ebd", method: "GET", headers : { "Authorization":"Bearer "+token, "Content-Type":"application/json;charset=UTF-8", "Host": "localhost:8080", "Accept": "application/json, text/plain" }, parameters: { "limit" : 3, "useCache" : "NONE" }, //content: "GETs don't have content!", err: function(status, headers, content) { //errorCallback for linguistic completion throw "Request got bad response: " + status + " " +content; }, resp: function(status, headers, content) { //responseCallback //try to retrieve the HttpBuilder object but no success //var result = JSON.parse(headers); //print(result); print(content); return true; //will print in wrapping print() } }));
-
@phildunlap
Thank you for your prompt reply. It works like a breeze.In my opinion, this is a powerful tool that open up the doors to communicate with internet of things / web content. In addition it provide flexibility to integrate your creativity into application.
"Logic will get you from A to B. Imagination will take you everywhere".