• 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

    Use the API to query a set of tagged points for rollups over a time period

    User help
    1
    1
    641
    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.
    • phildunlapP
      phildunlap
      last edited by phildunlap

      Someone recently asked over the phone for the pure JavaScript example of getting a set of point values through the API based on tags. The solution (currently) is to query the data points first, then compose a list to submit to the point-values endpoint, like,

      var token = "Token auth!";
      var baseUrl = 'http://localhost:8082/rest';
      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;
      }
      
      valuesRequestBody = {
        "dateTimeFormat": "YYYY-MM-dd'T'HH:mm:ss.SSSZ",
        "fields": [
          "XID",
          "VALUE"
        ],
        "from": "2018-10-16T18:43:20.111Z",
        "limit": 1000,
        "timePeriod": {
          "periods": 1,
          "type": "HOURS"
        },
        "timezone": "America/Denver",
        "to": "2018-10-19T18:43:20.111Z",
        "truncate": true,
        "xids": [
        ]
      }
      
      getDataPoints = newHttpRequest('GET', baseUrl + '/v2/data-points?eq(tags.device,example)&limit(100)', null);
      getDataPoints.onreadystatechange  = function() {
      	if (getDataPoints.readyState == XMLHttpRequest.DONE) {
      		var dataPoints = JSON.parse(this.responseText).items;
      		var dpXids = []
      		for(var k = 0; k < dataPoints.length; k+=1)
      			dpXids.push(dataPoints[k].xid);
      		valuesRequestBody.xids = dpXids;
      		getPointValues.send(JSON.stringify(valuesRequestBody));
      	}
      }
      
      getPointValues = newHttpRequest('POST', baseUrl + '/v2/point-values/multiple-arrays/time-period/ALL', {"Content-Type": "application/json"});
      getPointValues.onreadystatechange  = function() {
      	if (getPointValues.readyState == XMLHttpRequest.DONE) {
      		//var response = JSON.parse(getPointValues.responseText); //Then do stuff
      		console.log(getPointValues.responseText);
      	}
      }
      
      getDataPoints.send(null);
      
      

      This JavaScript will query the data points for up to 100 with the device tag 'example' and then request up to 1000 values for each (because it's a multiple arrays, single arrays the limit applies to all), where a 'value' in this context is a one hour rollup of ALL statistics options.

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