I am testing an externalEventHandler that would create a ticket in FreshService and return the ticketID back to the caller. I have browsed through a lot of serverless sample apps in GitHub - they all use console.log to log the response from the API, but I want to return the response back to the caller. I found renderData to be the way and here is how I am using it, but it is resulting in error.
Here is the relevant portion of the code…
onExternalEventHandler: async function (args) {
var remote_url = "https://something";
var options = {
headers: { "Content-Type": "application/json" },
body: JSON.stringify(args.data),
};
$request.post(remote_url, options).then(
function (data) {
//"data" is a json string with status, headers, and response.
console.info("response back at: " + Date());
console.info(JSON.stringify(data.response, null, 4));
renderData(null, {
success: true,
data: JSON.stringify(data.response, null, 4),
});
},
function (err) {
console.info("error back" + JSON.stringify(err, null, 4));
renderData(null, { success: false, error: err });
}
);
}
the ticketID is printed in the console properly. but it is not returned to the caller. Instead I get this error in the console. Can someone tell me what I am doing wrong? I tried converting the then blocks into synchronous using await and even tried the axios package, but all result in the same error