I'm using the attachment and ticket api for creating a Zendesk ticket with an attachment. The ticket gets created successfully and even generates a thumbnail for the attached file with the correct file name! But when I download and try to open the file, it cannot be opened and the file is only a few hundred bytes.
Here's the Ajax call for creating the attachment first:
{
url: "https://{obscured}.zendesk.com/api/v2/uploads?filename="+file_name,
type: "POST",
headers: {
"Authorization": "Basic "+wp_helper.zendesk_token,
"Content-Type": file_mime,
},
data: JSON.stringify({
"content_type": file_mime,
"content_url": file_url,
"file_name": file_name,
"size": file_size,
})
}
And here's the nested Ajax call for creating the ticket with the generated file token from the parent ajax call:
{
url: "https://{obscured}.zendesk.com/api/v2/tickets",
type: "POST",
headers: {
"Authorization": "Basic "+wp_helper.zendesk_token,
"Content-Type": "application/json",
},
contentType: "application/json",
data: JSON.stringify({
"ticket": {
"comment": {
"body": comment,
"uploads": [
file_token
]
},
"requester": { "locale_id": 1, "name": full_name, "email": email },
"subject": subject
}
})
}
I've double checked all variables are correctly formatted according to documentation and everything looks good. The weirdest part is the ticket is created with an attachment with the correct file name, but the file somehow does not get created properly on Zendesk.
Any thoughts?
What kind of file are you trying to upload?