I have a code like below. I am running a calling a function searchApiData. In searchApiData, when I log data in console I can see values of body. But when I see from exports.readData console.log(returnData), the value is always empty. Anyone know how I can get the data of the body in searchApiData?
exports.readData = functions.https.onRequest(async (req, res) => {
var returnData = "";
for (var a = 0; a < emailList.length; a++) {
returnData = searchApiData(emailList[a]);
console.log(returnData);
}
})
function searchApiData(email) {
fsData = "";
const options = {
method: 'GET',
json: true,
url: FS_URL + 'api/lookup?f=email&q='+email+'&entities=contact',
headers: {
"Authorization": "Token token=" + FS_API_KEY,
"Content-Type": "application/json"
}
};
//call the request
request(options, function(error, response, body) {
if(!error && response.statusCode == 200){
console.log(body);
fsData = body;
} else{
console.log(error);
}
});
return fsData;
}