Economy API Example Using JS
Scheme MITS

Economy API provides a very simple interface by which the user can fetch data from the CMIE Databases.

full example

 

function SCHEME_MITS()
  {
  var postvar= new FormData();
  postvar.append("apikey", "YOUR_API_KEY");
  postvar.append("scheme", "MITS");
  postvar.append("indicnum", "12692320,12252477,12692320,96653,15551738,2,15551706,12677767");
  postvar.append("freq", "Q");
  postvar.append("nperiod", "14");
  //
  var xmlHttp= new XMLHttpRequest();
  xmlHttp.onreadystatechange= function()
    {
    if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
      {
      var jdata= JSON.parse(xmlHttp.responseText);
      mktable(jdata);
      document.getElementById("json").innerHTML= JSON.stringify(jdata, undefined, 2);
      };
    };
  xmlHttp.open("post", "https://economyapi.cmie.com/query.php");
  xmlHttp.send(postvar);
  return 0;
  };
    
Scheme MIDS

Economy API provides a very simple interface by which the user can fetch data from the CMIE Databases.

XXXX

function SCHEME_MIDS()
  {
  var postvar= new FormData();
  postvar.append("apikey", "YOUR_API_KEY");
  postvar.append("scheme", "MISD");
  postvar.append("indicnum", "12692320,12252477,12692320,96653,15551738,2,15551706,12677767");
  postvar.append("freq", "Q");
  postvar.append("date", "20090630,20090331,20081231,20070930,20061231,20050930,20050331");
  //
  var xmlHttp= new XMLHttpRequest();
  xmlHttp.onreadystatechange= function()
    {
    if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
      {
      var jdata= JSON.parse(xmlHttp.responseText);
      mktable(jdata);
      document.getElementById("json").innerHTML= JSON.stringify(jdata, undefined, 2);
      };
    };
  xmlHttp.open("post", "https://economyapi.cmie.com/query.php");
  xmlHttp.send(postvar);
  return 0;
  };
    
Scheme SITS

Economy API provides a very simple interface by which the user can fetch data from the CMIE Databases.

XXXX

function SCHEME_SITS()
  {
  var postvar= new FormData();
  postvar.append("apikey", "YOUR_API_KEY");
  postvar.append("scheme", "SITS");
  postvar.append("indicnum", "12692320,12252477,12692320,96653,15551738,2,15551706,12677767");
  postvar.append("freq", "A");
  postvar.append("frdt", "20010630");
  postvar.append("date", "20090630");
  //
  var xmlHttp= new XMLHttpRequest();
  xmlHttp.onreadystatechange= function()
    {
    if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
      {
      var jdata= JSON.parse(xmlHttp.responseText);
      mktable(jdata);
      document.getElementById("json").innerHTML= JSON.stringify(jdata, undefined, 2);
      };
    };
  xmlHttp.open("post", "https://economyapi.cmie.com/query.php");
  xmlHttp.send(postvar);
  return 0;
  };
    
Parsing the downloaded JSON and making a table

Economy API provides a very simple interface by which the user can fetch data from the CMIE Databases.

XXXX

function mktable(o)
  {
  var _table_= document.createElement('table');
  var _tr_= document.createElement('tr');
  var _th_= document.createElement('th');
  var _td_= document.createElement('td');
  var meta= _table_.cloneNode(false);
  //
  for(var k in o.meta)
    {
    var tr= _tr_.cloneNode(false);
    var key= _td_.cloneNode(false);
    var val= _td_.cloneNode(false);
    key.appendChild(document.createTextNode(k));
    tr.appendChild(key);
    val.appendChild(document.createTextNode(o.meta[k]));
    tr.appendChild(val);
    meta.appendChild(tr);
    };
  var mtab= document.getElementById("mtab");
  if(mtab.hasChildNodes())
      mtab.replaceChild(meta, mtab.lastChild);
  else
      mtab.appendChild(meta);
  //
  var table= _table_.cloneNode(false);
  for(var i= 0; i < o.head.length; i++)
    {
    var tr= _tr_.cloneNode(false);
    for(var j= 0; j < o.head[i].length; j++)
      {
      var th= _th_.cloneNode(false);
      var cellValue= o.head[i][j];
      th.appendChild(document.createTextNode(o.head[i][j] || ''));
      tr.appendChild(th);
      }
    table.appendChild(tr);
    };
  for(var i= 0; i < o.data.length; i++)
    {
    var tr= _tr_.cloneNode(false);
    for(var j= 0; j < o.data[i].length; j++)
      {
      var td= _td_.cloneNode(false);
      td.setAttribute("align", j == 0 ? "left" : "right");
      var cellValue= o.data[i][j];
      td.appendChild(document.createTextNode(o.data[i][j] || ''));
      tr.appendChild(td);
      }
    table.appendChild(tr);
    };
  var jtab= document.getElementById("jtab");
  if(jtab.hasChildNodes())
      jtab.replaceChild(table, jtab.lastChild);
  else
      jtab.appendChild(table);
  }
    

Use of CMIE Product implies acceptance of the usage agreement & privacy policy   ♦   FAQs   ♦  Diagnosis