Hello all,
I am working with a client that wants to setup a middleware for ticket attachments. They are sending a Base64 encoded file to the middleware, which should then be sent to Freshservice via an API call. They can only send the file information in the following object (fields have been changed to mask proprietary values):
{
"sys_id": "1234567890123467890",
"file_name": "Test document.docx",
"uploaded_by": "test.user",
"size": "13225",
"content_type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"content": "AACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
}
In this object the “content” field contains the Base64 encoded file data.
I have attempted to setup the following function:
app.put('/api/ticket-integration/v1/tickets/:id/attachments', jsonParser, (req, res) => {
unirest
.put("https://(my domain).freshservice.com/api/v2/tickets/" + req.params.id)
.headers({
"Authorization" : "Basic (my encoded API key)",
"Content-Type" : "multipart/form-data",
})
.attach('attachments[]', req.body.content,
{
filename: req.body.file_name,
contentType: req.body.content_type,
knownLength: req.body.size,
})
.end(function (response) {
if (response.status < 400) {
console.log(`Attachment upload successful on ticket ${req.params.id}.`);
res.status(200).send('Attachment uploaded successfully' + JSON.stringify(response));
}else{
console.log({"attachment body": response.body, "attachment status": response.status});
}
});
});
This gives me the following error
node:events:491
throw er; // Unhandled 'error' event
^
Error: ENOENT: no such file or directory, open 'C:/file/path/(Base64 encoded file contents)'
I am not sure what value to put in the unirest call instead of req.body.content, but I know that is should be the file path. I am also not sure if it is even possible to send encoded files through the Freshservice API.
Has anyone found a way to be able to send this through?
Please let me know if there is any additional information I can provide, and thank you for taking the time to look through my post.