Creating tickets with attachments using serverless apps

In this post, let us see how we can use the unirest package to create a :freshdesk: freshdesk ticket with attachments from our serverless app. We will be making use of unirest specifically because it offers a simple interface & can attach files located remotely (remote file stream). However, feel free to use a different package if it serves the purpose better. Ideally, these files would reside in a file storage service that our app can securely access.

Note that this snippet should not be consumed as such and should ideally be refactored depending on the use case. Developers should test the application for varying scenarios - extensions, file size, no of attachments, file storage service latency, and ensure that the approach works well.


  1. Use fdk create to create a simple serverless boilerplate app.
  2. Proceed to add the code to server.js and modify manifest.json to include the dependencies
  3. Modify url and apiKey accordingly. Ensure to convert them to iparams while using them productively


var unirest = require('unirest');

exports = {
  onAppInstallHandler: function (args) {
    /* Substitute with the right handler and event. This is just to demo */
    logger('--Inside App Install Handler--');

function attFile(){
  logger("--Let's attach a file --");
  var url = "";
  var apiKey = "yyy";
  var headers = {
    "Content-Type": "multipart/form-data",
    "Authorization": "Basic " + apiKey
  var fields = {
    "description": "support ticket....",
    "subject": "support ticket...",
    "email": "",
    "status":"2", // certain fields are required during creation
// Lets use of unirest to attach files from our secure file store/s3/...
  .attach('attachments[]', '', {'filename': 'IcB62xb.png', 'contentType': 'image/png'})
  .attach('attachments[]', '', {'filename': 'DarkS1E4_Script.txt', 'contentType': 'text/plain'})
  .attach('attachments[]', '', {'filename': '2020-05-25_US_Mobility_Report_en.pdf', 'contentType': 'application/pdf'})
    logger("Response Status : " + response.status)
    if(response.status == 201){
      logger("Location Header : "+ response.headers['location'])
      logger("X-Request-Id :" + response.headers['x-request-id']);

function logger(dat){


  "platform-version": "2.3",
  "product": {
    "freshdesk": {
       "events": {
         "onAppInstall": {
            "handler": "onAppInstallHandler"
  "engines": {
    "node": "18.12.1",
      "fdk": "9.0.0"

will create a ticket like so:

It is very important to note that the file storage service you use must be secure and generate short-lived (signed preferably) links that are only valid for the ticket creation session. Upon creating the ticket, you will notice that the attachments have a link of their own.


can we use unirest in the public apps?

1 Like

Yes, any well-maintained library can be used for HTTP requests with attachments. Attachments are not supported in Request API as it has restriction in the payload size.

It is allowed to use other libraries specifically for this use-case until it is supported within the platform.

1 Like

We have a scenario where we need to create a ticket using another ticket’s conversation. But here we need to attach attachments of the conversations and the ticket’s attachment. We are able to create the ticket with attachment but the file format is not retained.

We are getting the attachment URL as below,

@kishore , I found a response that I think might be help you,

Please see if it helps, if not please create a new topic on the forum :slight_smile:

1 Like

@Saif, Thanks for the information, it helped us to create the ticket with attachment, but while trying to create the ticket with attachment and with custom fields, we are getting the below error message
field: ‘custom_fields’,
message: ‘Value set is of type String. It should be a/an key/value pair’,
code: ‘datatype_mismatch’

Any suggestions or thoughts on this?

@kishore - If the problem persists, do you mind creating a new topic on the forum? Let’s see we can address it.

Hi @Hem

How would yo go on and create attachment with the new request method with fdk 9.0?