HelpDeskZ Community
API Issue - Printable Version

+- HelpDeskZ Community (http://community.helpdeskz.com)
+-- Forum: HelpDeskZ 2 (http://community.helpdeskz.com/forum-3.html)
+--- Forum: Support (http://community.helpdeskz.com/forum-5.html)
+--- Thread: API Issue (/thread-2477.html)



API Issue - seank1968 - 04-12-2023

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?


RE: API Issue - cord.schneider - 04-12-2023

(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*10242)])
    ]);



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"
}



RE: API Issue - seank1968 - 04-13-2023

Thanks!

Yes, turning off attachments in tickets solves the issue - and the messages are appearing in the ticket both from users and staff.

Tried using a filename with a valid extension, but that still gives me the error.

I've commented out the above part of Messages.php and that works - although it removes any validation so isn't a permanent solution!