Skip to main content


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 user@yourcompany.com:test -F "attachments[]=@/path/to/attachment1.ext" -F "attachments[]=@/path/to/attachment2.ext" -F "email=example@example.com" -F "custom_fields[category]=Primary" -F "custom_fields[department]=Testing" -F "subject=Ticket Title" -F "description=this is a sample ticket" -X POST 'https://domain.freshdesk.com/api/v2/tickets'



This is also the solution in python:

data = {

'email': 'test@test.nl',

.... ,

'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 = requests.post('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.