Hello,
I’m writing a custom enquiries service using the tickets API. I’m having issues with attachments. I’ve searched in the forum and others have the same issue, but without clear solution.
This is the error I get:
description: "Validation failed"
errors: Array [ {…} ]
0: Object { field: "attachments", message: "It should contain elements of type valid file format only", code: "datatype_mismatch" }
Yet I’m sending an array of objects as written in the documentation.
At the moment my server is reading an incoming form and parsing it with Formidable to deal with multi-part form data. The attachments are read with fs and attached to the request for the Freshdesk API.
This is the code:
app.post('/enquiry', (req, res) => {
const form = formidable({
maxTotalFileSize: 20 * 1024 * 1024,
})
form.parse(req, async (err, fields, files) => {
if (err) {
res.json(err)
return
}
const formData = new FormData()
for (const [key, value] of Object.entries(fields)) {
formData.append(key, value[0])
}
if (files.attachments) {
for (const a of files.attachments) {
formData.append('attachments[]', fs.readFileSync(a.filepath))
}
}
await fetch(`${process.env.FRESHDESK_ORIGIN_URL}/tickets`, {
method: 'POST',
body: formData,
headers: {
...headers,
},
})
.then((r) => r.json())
.then((r) => res.json(r))
})
})
thanks a lot for your help ![]()