04-12-2023, 06:13 PM
(This post was last modified: 04-12-2023, 06:15 PM by cord.schneider.)
(04-12-2023, 02:58 PM)seank1968 Wrote: Trying to add a new message to a ticket via the API with N8N but keep getting an error:
Code:[
{
"error":1,
"message":"File is not allowed."
}
]
Using the following endpoint: api/messages/create and adding:
ticket_id
replier: user
message: text....
I'm not trying to upload a file but it looks like it's expecting a file?
It seems that this bit of code in hdz/app/Controllers/Api/Messages.php is not working as expected:
PHP Code:
if($settings->config('ticket_attachment')){
$max_size = $settings->config('ticket_file_size')*1024;
$allowed_extensions = unserialize($settings->config('ticket_file_type'));
$allowed_extensions = implode(',', $allowed_extensions);
$validation->setRule('attachment', 'attachment', 'ext_in[attachment,'.$allowed_extensions.']|max_size[attachment,'.$max_size.']',[
'ext_in' => lang('Api.error.fileNotAllowed'),
'max_size' => lang_replace('Api.error.fileIsBig', ['%size%' => number_to_size($max_size*1024, 2)])
]);
}
The validation should only be added if you have configured HelpDeskZ to allow files to be attached to tickets (Setup> Tickets settings> Allow attachments). Even then, it's not being set as a required parameter, so you should be able to leave it out safely. I turned off Allow attachments and was able to create a message using the API - although it wasn't visible on the ticket.
My guess is there's a bug in the Validation library that HelpDeskZ is using.
Btw, I used the following JSON with Allow attachments turned on. It seems that passing in a filename with an allowed extension seems to 'fool' the validation.
Code:
{
"ticket_id": 10,
"message": "This is a test message",
"replier": "staff",
"staff_id": 1,
"attachment": "file.txt"
}