• Recent
    • Tags
    • Popular
    • Register
    • Login

    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.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    HttpBuilder.request()

    Scripting general Discussion
    2
    3
    1.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Desmond
      last edited by Desmond

      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=NONE

      result:

      {
        "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:
      null

      I 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

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by phildunlap

        Hi Desmond,

        It seems the first issue is a class cast exception for the excp function. You can remove this function and the err function will be used instead with status code -1. Thanks for bringing this to our attention! https://github.com/infiniteautomation/ma-core-public/issues/1489

        After that, I also had to modify the "useCache": "None" to be "useCache": "NONE" (other options are CACHE_ONLY and BOTH )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()
            }
        }));
        
        D 1 Reply Last reply Reply Quote 0
        • D
          Desmond @phildunlap
          last edited by

          @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".

          1 Reply Last reply Reply Quote 0
          • First post
            Last post