I have written a node.js Lambda function for my skill and I am having trouble with the return data from a http request call. My endpoint for this request is an SAP hana application that returns a JSON file. I have tested this separately, fixed some authentication problems that I was having. I finally made sure this worked separately.
Now, I have the following httpGet function:
function httpGet(query, callback) {
console.log("/n QUERY: "+ query);
//var path = '/LocationInformation_2/getLocationInformation_2.xsjs?location=';
//var url = 'https://' + host + path + query;
var options = {
//http://api.nytimes.com/svc/search/v2/articlesearch.json?q=seattle&sort=newest&api-key=
host: host,
path: '/LocationInformation_2/getLocationInformation_2.xsjs?location=' + query,
method: 'GET',
//headers: { 'Content-Type': 'application/json' }
json: true
};
var req = http.request(options, (res) => {
var body = '';
console.log('status code: ' + res.statusCode);
res.on('data', (d) => {
body += d;
});
res.on('end', function () {
console.log('body: ' + body);
callback(body);
});
});
req.end();
req.on('error', (e) => {
console.error(e);
});
}
And this function that calls it:
'getNewsIntent': function () {
httpGet(location, function(response) {
var output = response['change'];
var cardTitle = location;
var cardContent = output;
alexa.emit(':tellWithCard', output, cardTitle, cardContent);
// alexa.emit(':tell', 'Hi');
});
},
The problem now, is, that whenever I call on this getNewsIntent(), there is absolutely no text on the output. As suggested by @craig_h, I looked at my CloudWatch to maybe get some information. And I am getting the following messages.
So in getNews() I have the line 'console.log('body: ' + body)'. I do not see this body here. I also get a 302 Status Code. What could this mean?