Hi,
I am facing an issue in onTicketCreate and onTicketUpdate events not getting triggered in the serverless app
It working fine in local but not working in the custom app
Below is the Manifest.json file
{
"platform-version": "2.2",
"product": {
"freshservice": {
"events": {
"onTicketCreate": {
"handler": "onTicketCreateHandler"
},
"onTicketUpdate": {
"handler": "onTicketUpdateHandler"
},
"onScheduledEvent": {
"handler": "onScheduledEventHandler"
}
}
}
},
"whitelisted-domains": [
"https://app.lansweeper.com",
"https://api.lansweeper.com",
"https://cresthelpdesk.freshservice.com"
],
"engines": {
"node": "14.20.0",
"fdk": "8.5.0"
}
}
Below is the server.js file
exports = {
onTicketCreateHandler: async function (payload) {
try {
console.info("args ", JSON.stringify(payload));
let finalresult = [];
let i = 0;
let per_page = 20;
do {
i = i + 1;
console.log("I ", i);
let headers = {
"Content-Type": "application/json",
"Authorization": "Basic <%= encode(iparam.api_key) %>",
};
let url = `https://domain.freshservice.com/api/v2/products?per_page=${per_page}&page=${i}`
console.info("url ", url);
await $request.get(url, { headers }).then(function (data) {
// success
console.info("sites ", data);
let result = JSON.parse(data.response)
console.info("result ", result.products);
finalresult = result.products;
console.info("result ", finalresult.length);
}, function (err) {
// failure
console.error(err);
});
// success
} while (i < 551);
} catch (ex) {
console.log("ex ", ex)
}
},
onTicketUpdateHandler: function (payload) {
console.info("args 11 ", payload);
let headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <%= access_token %>"
};
let reqData = {
headers: headers,
isOAuth: true,
body: JSON.stringify({
"query": "{ authorizedSites { sites { id name } } }"
})
};
let url = "https://api.lansweeper.com/api/v2/graphql"
$request.post(url, reqData)
.then(function (data) {
// success
console.info("sites ", data);
}, function (err) {
// failure
console.error(err);
});
},
onScheduledEventHandler: function (payload) {
console.log("Logging arguments from onScheduledEvent: " + JSON.stringify(payload));
if (payload.data.account_id = "3") {
//your code to perform any actions
}
}
};
So I am not getting what is wrong in above structure?
Anybody can help
Thanks !!