Does anyone have an example of a call to the Intrinio financial data API? I am trying to reconcile their instructions with this Meteor Chef post but only getting halfway there. I am able to access their data via browser and via command line but not through my code. First time working with an API of any kind, appreciate any suggestions.
Also, I understand there is an npm package for an Intrinio client. I’m on Meteor 1.2.1, not using npm.
I’ve added the http
package and written the following in a client/lib file:
getData = function() {
HTTP.call('GET','api.intrinio.com', {
query: "/companies?ticker=AAPL",
authorization: "myUsername:myPassword"
},
function( error, response ) {
if(error) {
console.log("Error")
} else {
console.log(response)
}
});
};
In the console, this returns the following - I’m getting the right status code but the data is empty:
Object {
statusCode: 200,
content: "<!DOCTYPE html>↵<html>↵<head>↵ <link rel="stylesh…pFinance</title>↵</head>↵<body>↵↵</body>↵</html>↵",
headers: Object,
data: null}
The Intrinio instructions recommend the following, but I believe some of this is redundant:
var https = require("https");
var username = "myUsername";
var password = "myPassword";
var auth = "Basic " + new Buffer(username + ':' + password).toString('base64');
var request = https.request({
method: "GET",
host: "api.intrinio.com",
path: "/companies?ticker=AAPL",
headers: {
"Authorization": auth
}
}, function(response) {
var json = "";
response.on('data', function (chunk) {
json += chunk;
});
response.on('end', function() {
var company = JSON.parse(json);
console.log(company);
});
});
request.end();