Sending attachments using Freshdesk API

We are trying to send images as an attachment using API from Freshdesk. We want to create a new ticket along with multiple attachments. Getting the following error message when trying to implement the code from Github:

Message could not be sent. Mailer Error: {“description”:“Validation failed”,“errors”:[{“field”:“attachments”,“message”:“Unexpected/invalid field in request”,“code”:“invalid_field”}]}

Request help with the same

Hi @Surajit_Chaudhuri,
Good day! Welcome to the community!

can you please take a look at this document for more reference?

https://developers.freshdesk.com/api/#create_ticket_with_attachment

Thanks

Do you mind sharing the code that you used?

I am also facing the same issue.
While i am trying to hit the api for attachments i have tried sending it form my local file system as well as via a link but i get the same response. please help.
response - when i hit the request with correct basic auth and domain
{
“description”: “Validation failed”,
“errors”: [
{
“field”: “attachments”,
“message”: “It should contain elements of type valid file format only”,
“code”: “datatype_mismatch”
}
]
}

I am also facing the same issue while uploading attachment.
Please reply for any solution

After tinkering around, this worked for me.

headers = {'Authorization': f'Basic {apiKey}'}
files = [
            ('attachments[]', open(
                'file_1.jpg', 'rb')),
            ('attachments[]', open('file_2.pdf', 'rb')),
            ('email', (None, 'test@gmail.com')),
            ('subject', (None, 'Pickup & Delivery')),
            ('description', (None, 'TEST TEST Testing')),
            ('custom_fields[cf_fcr]', (None, 'Yes')),
            ('custom_fields[cf_sub_category]',
             (None, 'Delay in Shipment Delivery - Forward')),
            ('custom_fields[cf_issue_category]',
             (None, 'Shipment Delivery')),
            ('custom_fields[cf_awb_number]', (None, '333')),
            ('cc_emails[]', (None, 'test@gmail.com')),
            ('tags[]', (None, 'CARGO-ICRM')),
            ('type', (None, 'Query')),
            ('group_id', (None, '11')),
            ('name', (None, 'John')),
            ('priority', (None, '1')),
            ('status', (None, '2')),
        ]

r = requests.post(url, files=files, headers=headers)

If you use postman to convert the curl into Python requests, it uses data param which gives error such as

{'description': 'Validation failed', 'errors': [{'field': 'cc_emails', 'message': 'Value set is of type String.It should be a/an Array', 'code': 'datatype_mismatch'}, {'field': 'tags', 'message': 'Value set is of type String.It should be a/an Array', 'code': 'datatype_mismatch'}, {'field': 'custom_fields', 'message': 'Value set is of type String.It should be a/an key/value pair', 'code': 'datatype_mismatch'}]}

Use online curl conveters; they give the correct conversion. https://curlconverter.com/