I'm currently in the midst of developing my very first Node application, and I've hit a snag with unirest.get requests. My project features Node, Express, as well as the Act On API.
To speed up the setup process, I've opted to use the express generator.
The issue at hand is that I'm having difficulty passing the response to my route file. While I can clearly see the correct response from the Act On API in the console log, I'm unable to access the data within the templates.
function getTheList(callback) {
var Request = unirest.get('https://restapi.actonsoftware.com/api/1/list/l-0001')
.headers({
'Accept': 'application/json',
'Authorization': 'Bearer ' + access_token
})
.query({
"count": 20,
"fields": "First Name;Last Name;Email;"
})
.end(function(response, error) {
var data = response.body.data;
if (!error && response.statusCode == 200) {
callback(returnData(data));
} else {
console.log('Failed response');
}
});
}
function returnData(theData){
console.log(theData);
return theData;
}
module.exports.get = getTheList;
Within my routes file, you'll find the following code snippet used to retrieve this information:
var masterList = require('../acton/getMasterList');
var myListVar = masterList.get();
Any assistance on identifying where I may be going wrong would be tremendously helpful.