krkr
12/7/2015 - 2:19 PM

OVH IoT PaaS TS API - Javascript example

OVH IoT PaaS TS API - Javascript example

var tokenId  = '?'; 
var tokenKey = '?';
var metricName = '?';
var start = '?';

$.ajax({
  url: 'https://opentsdb.iot.runabove.io/api/query',
  type: 'POST',
  data: JSON.stringify({
    start: start,
    queries:[{
      metric: metricName,
      aggregator: 'avg',
      downsample: '15m-avg'
    }]
  }),
  contentType: 'application/json; charset=utf-8',
  dataType: 'json',
  beforeSend: function (xhr) {
      xhr.setRequestHeader ("Authorization", "Basic " + btoa(tokenId + ":" + tokenKey));
  },
  success: function(data) {
    console.log();
    $('#content').text(JSON.stringify(data, null, 2));
  }
});