I gone through with Error in establishing connection related threads here but i can't find any solution to solve this error.
my use case is to make http request to fetch tickets in my fresh desk account i use $reques API to make http request in my server.js .i run my app as a custom app.
i getting ** { status: 502, headers: {}, response: ‘Error in establishing connection’, errorSource: ‘APP’, attempts: 1 }** error in response
my fdk version is : 8.6.7
my node version is : v14.21.2
I little confused here. This event triggers when i update tickets in my freshdesk account so which browser tab i should send? ticket page in my fresh desk account or installation page .
It looks like the iparam named domain provides the fully-qualified domain name (FQDN) and not just the subdomain. (Notice the URL mentioned in the original screenshot at Feb 2, 2023, 2:10:42 PM.)
That log is truncated, @Kithiyon, so you don’t see the response. You need to call data.response to access the response. The object returned from $request.get(url, options) has these properties:
status: HTTP status code. number
headers: HTTP headers. object with each response header as key with its corresponding value.
response: The HTTP response body as a string.
(I assumed you had fixed this so I did not suggest this earlier)
Your code screenshot has mixed async...await with .then() Promise chaining. You should rewrite the function using one of the following:
Option 1:
exports = {
onTicketUpdateCallback: function (args) {
// ... rest of the code
$request.get(url, options)
.then(function (data) {
// success handler
}, function (error) {
// error handler
});
}
}
Option 2:
exports = {
onTicketUpdateCallback: async function (args) {
// ... rest of the code
try {
const res = await $request.get(url, options);
// Add success condition here
} catch (err) {
// Error handler
}
}
}
I have one more doubt. I want to send outbound mails so i make api request to this api end point but email not triggered.
I getting 400 bad request error.
I’m not sure my request payload is correct or not .
This is my server.js code
var btoa = require('btoa');
exports = {
onTicketUpdateCallback: function (args) {
let status = args['data']['ticket']['status'];
let subject = args['data']['ticket']['subject'];
let priority = args['data']['ticket']['priority'];
let apprvalStatus = args['iparams']['approvalflow'];
let api_key = args['iparams']['api_key'];
let domain = args['iparams']['domain'];
let to_mail = args['iparams']['Tomail'];
let from_mail = args['iparams']['FromMail'];
let email_body = args['iparams']['body'];
console.log(api_key)
console.log(domain)
console.log(to_mail)
console.log(from_mail)
console.log(email_body)
console.log(subject)
console.log(priority)
if (apprvalStatus == status) {
console.log("i'm in IF condition");
let payload = {
"email": to_mail,
"email_config_id": from_mail,
"status": status,
"subject": subject,
"priority": priority,
" description": `<div><p>${email_body}<p><div>`,
};
let headers = {
Authorization: `Basic ${btoa(api_key + ":X")}`,
"Content-Type": "application/json"
}
let options = {
method: "POST",
headers: headers,
body: JSON.stringify(payload),
}
console.log(options)
let url = `${domain}/api/v2/tickets/outbound_email`;
console.log(url)
$request.post(url, options)
.then(
function (data) {
console.log(data.response)
},
function (error) {
console.log(error)
}
);
}
else {
console.log("not working")
}
},
};