Create ticket with custom fields and attachments (multipart/form-data)

Not sure where the best place for this is, but wanted to add an example to send a custom field when using the form method (required when sending attachments):

notice the custom_fields[field_name] syntax, I could not find this anywhere else, but the support team at freshdesk responded to my question right away with the correct info, thanks!

curl -v -u -F "attachments[]=@/path/to/attachment1.ext" -F "attachments[]=@/path/to/attachment2.ext" -F "" -F "custom_fields[category]=Primary" -F "custom_fields[department]=Testing" -F "subject=Ticket Title" -F "description=this is a sample ticket" -X POST ''

5 people have this question
1 Comment

This is also the solution in python:

data = {

   'email': '',

   .... ,

   'custom_fields[filters]': 'filtervalue'


Having 'custom_fields': { 'filters': 'filtervalue'} does not work on a multipart/form-data request.

You can send all data as a dict like in the above example.

Make sure all values in the dict are a string.

In the request, it is easiest to send the ticket info in data= and the files in files=:

sendrequest ='https://freshdeskdomain/api/v2/tickets, files=files, data=data, auth=(targetToken, targetPass))

The files can be a dict of the following:

file = ('attachments[]', (filename, open(fullpath, 'rb'), the_content_type))

'attachments[]' seems to be mandatory.

Login or Signup to post a comment