In my handlers, I have an intent (SelectGardenIntent) that obtains the user_id (needed for following HTTP requests) from the access token successfully, as well as a variable called gardenNumber which is a slot value. To complete the request, I need two other values, the garden_id and the dev_id. I use this gardenNumber and pass it into a function called getGardenId, which will assign the one of the data from the HTTP request to the variable garden_id I have defined in index.js. There are no issues with user_id and gardenNumber. When the function is run, there are no errors from the request, but the callback function with the response is also not executed. The user_id, "about to enter request", and "req done" are correctly logged when tested, but the other log statements in the callback function are not since it is not run. The result is that garden_id is undefined. dev_id is obtained in another method that depends on this garden_id, so dev_id is also undefined. Please help me on this issue. I have pasted the relevant code below.
... var user_id, garden_id, dev_id; ... function getGardenId (gardenNumber) { console.log(user_id); var path = '/api/rest/client/getgardeninfo?&userid=' + user_id; var options = { hostname: server_ip, port: 80, path: path, method: 'GET' } console.log("about to enter request"); var req = http.request(options, (res) => { console.log('entered request'); if (res.statusCode === 200) { console.log('successful request'); res.setEncoding('utf8'); var body = ""; res.on('data', (chunk) => { console.log('adding data'); body += chunk.toString(); }); res.on('end', () => { var obj = JSON.parse(body); console.log('successfully parsed'); if (obj.error === 200) { console.log('##gardenid successfully obtained'); garden_id = obj.data[gardenNumber - 1].id; } else { console.log("parsing error"); } }); } else { console.log("failed request"); } }); } catch(e) { console.log("ERROR"); } req.on('error', (e) => { console.error(`problem with request: ${e.message}`); }); req.on('finish', () => { console.log('ended'); }) req.end(); console.log("req done"); } ... var handlers = { ... 'SelectGardenIntent': function () { //var filledSlots = delegateSlotCollection.call(this); var gardenNumber = this.event.request.intent.slots.Garden.value; user_id = this.event.session.user.accessToken; getGardenId(gardenNumber); getDevId(garden_id); this.emit(':tell', `OK, garden ${gardenNumber} selected, user id is ${user_id}, garden id is ${garden_id}, device id is ${dev_id}`); } ... }