Issue Creating Ticket with Attachment - JSON

Hello,

I am trying to create a ticket with an attachment and am having an issue with the attachment segment. The return I am getting is 400: Bad Request. The file does exist already at the time of sending the request.

Everything works fine until I add the attachments segment. The documentation only shows a curl example. Does anyone know how the properties are for the attachments segment if using JSON?

{
“ticket”: {
“email”: “bob@test.com”,
“cc_emails”: [
test@test.com
],
“subject”: “Test”,
“description”: “API Test Please Delete!”,
“priority”: 2,
“status”: 2,
“source”: 2,
“urgency”: 2,
“impact”: 2,
“custom_fields”: {
“customer_ticket_nubmer”: “12345”,
“product”: “Test”,
“product_category”: “Test”,
“product_family”: “Test”
},
“attachments”: [
{
“uri”: “file:///C:/Users/dcormier/Downloads/export.csv”,
“type”: “text/csv”,
“name”: “test.csv”
}
]
}
}

Hi @dcormier ,

Hope you’re doing well!

The curl command in the documentation works as expected. You can try using it in Postman by adding the following command:

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'

The command should work fine since the body is sent as form data (due to the attachment).

For more details, you can refer to this documentation adding attachments:

Please give it a try and let me know how it goes!

Hope this helps.

Thanks
Anish

To continue with what Anish is saying.
The attachment needs to be a file stream as part form-data of the request

Looking at your JSON - it’s not the JSON for a create ticket request. You have it wrapped with the key of 'ticket'. So I don’t know if you are sending this to a language-specific library.

For better help try to give us all the information. What language or tool (curl,postman,…) . Show us some simple sample code that demonstrates the issue.

As Anish says - start with the ‘curl’ command and go from there.
Curl will show you the headers and form data as well.