Tuesday, 4 April 2017

Openfigi REST API in node js

I am trying to run the following Nodejs program to retrieve data from OpenFigi. But, not getting any information whereas curl request returns the data.

var request = require('request');

var options = {
    url: 'https://api.openfigi.com/v1/mapping',
    data: '[{"idType":"ID_WERTPAPIER","idValue":"851399","exchCode":"US"}]',
    headers: {
         'Content-Type': 'text/json'
      }  }; 

function callback(error, response, body) {
   if (!error && response.statusCode == 200) {
       var info = JSON.parse(body);
       console.log(info);
   } 
}

request(options, callback);

The following curl request returns the data

curl -v POST 'https://api.openfigi.com/v1/mapping'   \
   --header 'Content-Type: text/json'             \
   --data '[{"idType":"ID_WERTPAPIER","idValue":"851399","exchCode":"US"}]'

Result:

 [
  {
    "data": [
    {
    "figi": "BBG000BLNNH6",
    "securityType": "Common Stock",
    "marketSector": "Equity",
    "ticker": "IBM",
    "name": "INTL BUSINESS MACHINES CORP",
    "uniqueID": "EQ0010080100001000",
    }
   ]
  }
]

Could you please help to fix the nodejs program.

Thanks, Saravana



via saravana

No comments:

Post a Comment