How to download freshdesk ticket attachments to upload to remote API?

I’ve used the following structure to get a link from an external api and generate an attachment on a freshdesk ticket on a serveless!

Getting the ticket attachment to send to another api I never tested, but maybe that helps:

indent preformatted text by 4 spaces
   var   unirest  =  require('unirest');
   update_ticket(args){
	var domain = args.iparams.domain;
	var api_key = args.iparams.api_key;

	var url = `${domain}/api/tickets/${args.id}`;		
	var headersOpt = {  
		"Authorization": "Basic "+base64.encode(`${api_key}:x`)
	};		
	unirest.put(url)
		.headers(headersOpt)
		.attach('attachments[]', args.url_attachment)
		.end(function (response) {
			console.log(response.body);
			if (response.status === 200) {	
				renderData(null,{"body": response.body, "status": response.status});
			}else{
				renderData(null,{"body": response.body, "status": response.status});
			}
		});
}
5 Likes