Issue in creating a ticket with attachment

Hello Team,

I am trying to create a ticket in Freshdesk using the attachments.

Steps:

  1. First, I am downloading the files using a middleware (node js project)
  2. Once the files are downloaded, then I am using the “unirest” npm library to create a ticket in Freshdesk account with the attachments

But I am facing issues in creating the ticket with the attchments.

Download the source code using below URL.

Please let me know if I am missing something here as I am not able to create the Freshdesk ticket with attachment/attachments.

Regards,
Akhil S Kulkarni

Hello Akhil

Am a bit confused as to why you are writing your own express application. You can try to bootstrap a Freshworks app following Quick Start. You can use request module to make create ticket API calls

Also, I would love to hear out what you are trying to achieve to understand better and help out

1 Like

@shravan.balasubraman

Issue: I need to get the attachments from the conversation and create a new ticket.

If I use the URL for the attachment to create a new ticket, it is not working.

So, I am downloading the URL in a folder using a middleware and then attaching the same attachment while creating a new ticket.

Please let me know if there is any alternate solution.

Hi @Akhil_Kulkarni

Creating ticket with attachment requires ticket fields sent as form fields. As per the unirest doc this should be as following:

unirest
  .post('http://mockbin.com/request')
  .headers({'Content-Type': 'multipart/form-data'})
  .field('parameter', 'value') // Form field
  .attach('file', '/tmp/file') // Attachment
  .then(function (response) {
    console.log(response.body)
  }

However In your server.js you are passing it as following;

unirest
        .post(url)
        .headers(headers)
        **.field(fields)**
        .attach("attachments[]", `./files/${file1}`)

Have you tried setting fields like mentioned in doc-- i.e. …field('parameter', 'value') // Form field

From API documentation example for a ticket with attachment–

curl -v -u yourapikey:X -F "attachments[]=@/path/to/attachment1.ext" -F "attachments[]=@/path/to/attachment2.ext" -F "email=example@example.com" -F "subject=Ticket Title" -F "description=this is a sample ticket" -X POST 'https://domain.freshdesk.com/api/v2/tickets'
2 Likes

@Raviraj

Please find the attached screenshot and let me know if something needs to be changed from my side.

Hi @Akhil_Kulkarni,

I see, there are multiple validation errors and reasons for them. Were you able to address them? If not, are there any issues?