I am trying to add a note with an attachment to a Freshservice ticket using python but it is not working.
Below is my code:
# * Construct the Freshservice URL
fresh_service_url = VALUE_URL_BASE_FRESHSERVICE_NOTE.format(
self.domain,
self.ticket['id']
)
# * Make the API call to get the ticket details
response = requests.post(
fresh_service_url,
headers={
"Content-Type": "multipart/form-data",
"Authorization": f"Basic {api_key}"
},
files = [
('attachments[]', ('test.txt', open("test.txt", 'rb'), 'text/plain')),
]
)
# * Log the freshservice response
logging.info(f"fs note response: {response.text}")
# * Checks if update is successfull
if response.status_code != 201:
raise FreshserviceException(f"The note couldn't be added to ticket {self.ticket['id']}: {response.text}")
However, when running it, I am getting the below error:
File ".../freshservice_ticket.py", line 62, in add_note_with_attachments
raise FreshserviceException(f"The note couldn't be added to ticket
{self.ticket['id']}: {response.text}")
models.exceptions.FreshserviceException:
The note couldn't be added to ticket 777: {"description":"Validation failed","errors":[{"field":"--4bae5bb5c9d1b1a219beff9e504009d4\r\nContent-Disposition: form-data; name","message":"Unexpected/invalid field in request","code":"invalid_field"}]}
Can someone please help me ?