• 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

    How to use "/events/data-point-summaries" API?

    How-To
    2
    10
    1.1k
    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.
    • M
      Malaguena
      last edited by

      Hello!

      I am trying to use /events/data-point-summaries API function which is shown in swagger. I could not get a response.
      The code used is shown below.

      How should I use /events/data-point-summaries API to get a successful response?

      Thanks!

      
      var eventsum = HttpBuilder.request({
          path: "http://localhost:8080/rest/v2/events/data-point-summaries",
          method: "POST",
          headers: {
              "Host": "10.167.35.76:8080",
            "Accept": "application/json, text/plain",
              "Content-Type": "application/json;charset=UTF-8",
              "Authorization":
                  "Bearer+"token,
          },
          parameters:{
              "xids":[
                "DP_a638a144-5b1d-45c7-bcb1-b89097cbb08a",
                "DP_a7e64a32-8229-4909-95e3-a992208382c4"
              ]},
          err: function (status, headers, content) {
              throw "Request got bad response: " + status;
          },
          resp: function (status, headers, content) {
              return JSON.parse(content);
          },
      });
      
      1 Reply Last reply Reply Quote 1
      • MattFoxM
        MattFox
        last edited by

        @nurr said in How to use "/events/data-point-summaries" API?:

        "Bearer+"token,

        Should be "Authorization":"Bearer " + token,

        Do not follow where the path may lead; go instead where there is no path.
        And leave a trail - Muriel Strode

        1 Reply Last reply Reply Quote 0
        • M
          Malaguena
          last edited by

          @MattFox yes I have done this as you said. When I post, still couldn't get a response. Are we posting parameters in true format?

          We use Mango core version 3.7.5.

          1 Reply Last reply Reply Quote 0
          • MattFoxM
            MattFox
            last edited by MattFox

            @nurr said in How to use "/events/data-point-summaries" API?:

            /events/data-point-summaries

            Looking a little closer, it would appear the XIDS are in fact the xids of the event handlers themselves, not the datapoints.
            ie:EH_42e3843c-3510-484c-9a50-00c247834c79.

            EDIT: I could be wrong. have you actually tried using the swagger api tester?
            EDIT2: Just tested for you on 3.77: - it's datapoints, test with the swagger API then let's look at your script.

              {
                "xid": "40281405",
                "counts": {}
              }
            ]
            

            Fox

            Do not follow where the path may lead; go instead where there is no path.
            And leave a trail - Muriel Strode

            1 Reply Last reply Reply Quote 0
            • M
              Malaguena
              last edited by

              @MattFox , I have tested via swagger-ui page. When I use datapoint xids it responses properly on swagger-ui.

              I have used the code below in the global script, and getting response like below.

              Response:

              {"cause":"MismatchedInputException: Cannot deserialize instance of `java.lang.String[]` out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]","mangoStatusName":null,"mangoStatusCode":-1,"localizedMessage":"Bad Request — com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String[]` out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]"}
              
              function httpReq(url,method,callback,headers,params)
              {//Second format, full request
                  if(headers===undefined){headers={};}
                  if(params===undefined){params={};}
                  if(method=="get")
                  {
                  HttpBuilder.get(url,headers,params)
              	.err(function(status, headers, content) { //setErrorCallback for linguistic completion
              		  //setErrorCallback for linguistic completion
                          	print(status);	print(content);
              	}).resp( 
              	 callback
              
               ).excp(function(exception) { //setExceptionCallback
              		throw exception.getMessage();
              	}).execute();
                  }
                  else
                  {
                       HttpBuilder.post(url,headers,params)
              	.err(function(status, headers, content) { //setErrorCallback for linguistic completion
              		  //setErrorCallback for linguistic completion
                          	print(status);	print(content);
              	}).resp( 
              	 callback
              	
              	 ).excp(function(exception) { //setExceptionCallback
              		throw exception.getMessage();
              	}).execute();
                  }
              }
              
              var url = "http://10.167.35.76:8080/rest/v2/events/data-point-summaries";
              var method = "post";  //Or "post"
              var headers = {ContentType : "application/json", Authorization: "Bearer eyJhbGciOiJFUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTU5MjQ1OTMyNiwiaWQiOjEsInYiOjEsInR5cCI6ImF1dGgifQ.AZBrTRgtnP7W-88iiNbTn8oHFtjAMieGzEtC-Lr2uLRcZsDftzHKqct-gABlixlEErQqrmTRxF-y8aTprxld59tYAVdcggptg-jyJ-tPHqKSiaIY9VwNnefsxDf-qUTRQ9WeGi95jf1pQDhDQnSqsNsJ_HAFrD_Z0DiFoQwY9Z01iWcE" };
              
              var parameters ={xids:["DP_c244739c-86cd-43e3-95c5-b76acf4730b2"]}; /* If needed exclude if not*/
              
              var handleResponse = function(status, headers, content)
              {
                 var data = JSON.parse(content);
              
                print(data);
              
              }
              
              httpReq(url, method, handleResponse , headers);
              
              1 Reply Last reply Reply Quote 0
              • MattFoxM
                MattFox
                last edited by

                Aha! I see why now! You need to send it in the body of the message not as a parameter!

                Ok sorry to be a pain, but a different approach is needed - this will be with javascript's xmlhttp ajax handler.

                Do not follow where the path may lead; go instead where there is no path.
                And leave a trail - Muriel Strode

                1 Reply Last reply Reply Quote 0
                • MattFoxM
                  MattFox
                  last edited by MattFox

                  This was written by Phil Dunlap, so i can't take any credit here: but this will help you get your request out.
                  First make a global script by the name of XMLHttp Request: the function to call is called newHttpRequest:

                  function newHttpRequest(method, url, headers) {
                  	var http = new XMLHttpRequest();
                  	http.open(method, url, true);
                  	
                  	http.setRequestHeader("Accept", "application/json")
                  	http.setRequestHeader("Authorization", "Bearer " + token)
                  	if(headers != null) {
                  		for(var header in headers)
                  			http.setRequestHeader(header, headers[header]);
                  	}
                  			
                  	return http;
                  }
                  

                  Next:
                  Your API body:

                  requestBody = {
                    "xids": [ //plonk xids in this array
                    ]
                  }
                  

                  Your Methods:

                  var headers = {ContentType : "application/json", Authorization: "Bearer eyJhbGciOiJFUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTU5MjQ1OTMyNiwiaWQiOjEsInYiOjEsInR5cCI6ImF1dGgifQ.AZBrTRgtnP7W-88iiNbTn8oHFtjAMieGzEtC-Lr2uLRcZsDftzHKqct-gABlixlEErQqrmTRxF-y8aTprxld59tYAVdcggptg-jyJ-tPHqKSiaIY9VwNnefsxDf-qUTRQ9WeGi95jf1pQDhDQnSqsNsJ_HAFrD_Z0DiFoQwY9Z01iWcE" };
                  
                  var getEventSummary = newHttpRequest('POST', "http://10.167.35.76:8080/rest/v2/events/data-point-summaries", headers);
                  getEventSummary.onreadystatechange  = function() {
                  	if (getEventSummary.readyState == XMLHttpRequest.DONE) {
                  		//var response = JSON.parse(getEventSummary.responseText); //Then do stuff
                  		console.log(getEventSummary.responseText);
                  	}
                  }
                  getEventSummary.send(JSON.stringify(valuesRequestBody));
                  

                  Edit sorry Nurr, I've mislead you. The embedded javascript engine doesn't support this.
                  You'd have to do this from an external system.

                  Do not follow where the path may lead; go instead where there is no path.
                  And leave a trail - Muriel Strode

                  1 Reply Last reply Reply Quote 0
                  • MattFoxM
                    MattFox
                    last edited by

                    @terrypacker , made a bit of a blunder here. Does the HttpRequest system support a POST body? and if so how can it be implemented?
                    It'd be good to add it to the wrapper I wrote...
                    Fox

                    Do not follow where the path may lead; go instead where there is no path.
                    And leave a trail - Muriel Strode

                    1 Reply Last reply Reply Quote 0
                    • M
                      Malaguena
                      last edited by

                      Hi! @MattFox @terrypacker

                      Is there any update about it?

                      Thanks

                      1 Reply Last reply Reply Quote 0
                      • MattFoxM
                        MattFox
                        last edited by

                        Not without writing your own API and using that to make your query then calling that from mango instead.

                        Do not follow where the path may lead; go instead where there is no path.
                        And leave a trail - Muriel Strode

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