Error code 502 while trying to fetch the ticket details in the production environment

Hi,

When I am trying to get the ticket details by fetch ticket API, I got the error code 502 and the error message is “Error in establishing connection”.

Code Sample

async function fetchData(args)
  {
    return new Promise(function(resolve,reject){
      var  new_tid=args['data']['ticket']['id'];
      console.log("this is new ticket id",new_tid); 	
	      var options={
      method:"GET",
      url:`${getDomain(args)}/api/v2/tickets/${new_tid}`,
      headers:{
        "Authorization": 'Basic <%= encode(iparam.api_key) %>',
        'content-Type':'application/json'
      }
    };
    request(options,(err,res,body)=>{
	  
      if(body!='')
      {
        //fcon=JSON.parse(body);
        console.log("fetch data",body); 
		console.log("Response",res);console.log("err",err);
		resolve(body.response);
	  }
	  else {
		console.log("err",err);
		reject(err);
	  }
})

You should not return a Promise from within an async function. An async function wraps any return type in a Promise anyway. So, you’d want to simplify the code here.

Please take a look at the Request Method documentation for Freshdesk. There are some sample apps as well.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.