Using the api function to create new ticket and getting system error 400 for two fields: due date and staff id. As mentioned in a previous question thread the due date still not working. The ticket is created with the appropriate staffID even though an error is generated. btw, I've tried using with staffID as a text and as a number. Here is the code:
$data = array(
'name' => 'new tickets',
'email' => 'xxxxxxxxxxxxxxxxx',
'staffId' => '8',
'topicId' => $svinptopicId,
// 'duedate' => $svinpduedate,
'duedate' => '12/08/2024',
'subject' => $svinpsubject,
'message' => $svinpmessage,
'companyid' => $svinpcompanyid,
'ip' => $_SERVER['REMOTE_ADDR'],
'attachments' => array(),
);

Server Information
osTicket Version v1.18.1 (0375576) — Up to date
Web Server Software Apache
MySQL Version 8.0.37
PHP Version 8.1.29
PHP Extensions
gdlib Used for image manipulation and PDF printing
imap Used for email fetching
xml XML API
xml-dom Used for HTML email processing
json Improves performance creating and processing JSON
mbstring Highly recommended for non western european language content
phar Highly recommended for plugins and language packs
intl Highly recommended for non western european language content
fileinfo Used to detect file types for uploads
zip Used for ticket and task exporting
APCu Improves overall performance
Zend Opcache Improves overall performance

  • KevinTheJedi replied to this.
  • cherrie

    I am using v1.18.1 and cannot replicate the staffId issue. If I add "staffId": 1, to my JSON payload it sets the Assignee appropriately. Not sure what's going on in your instance.

    As for the duedate issue it's due to a specific bit of code back from 1.7.x (circa 2013). To get it working you can apply the below patch:

    diff --git a/include/class.ticket.php b/include/class.ticket.php
    index a7573678..2e00fd59 100644
    --- a/include/class.ticket.php
    +++ b/include/class.ticket.php
    @@ -4370,7 +4370,7 @@ implements RestrictedAccess, Threadable, Searchable {
                 $ticket->email_id = $vars['emailId'];
     
             //Make sure the origin is staff - avoid firebug hack!
    -        if ($vars['duedate'] && !strcasecmp($origin,'staff'))
    +        if ($vars['duedate'] && in_array(strtolower($origin), ['staff', 'api']))
                 $ticket->duedate = date('Y-m-d G:i',
                     Misc::dbtime($vars['duedate']));
     
    diff --git a/include/api.tickets.php b/include/api.tickets.php
    index d160c324..bb8f7e94 100644
    --- a/include/api.tickets.php
    +++ b/include/api.tickets.php
    @@ -43,15 +43,22 @@ class TicketApiController extends ApiController {
                 foreach ($form->getFields() as $field)
                     $supported[] = $field->get('name');
     
    -        if(!strcasecmp($format, 'email')) {
    -            $supported = array_merge($supported, array('header', 'mid',
    -                'emailId', 'to-email-id', 'ticketId', 'reply-to', 'reply-to-name',
    -                'in-reply-to', 'references', 'thread-type', 'system_emails',
    -                'mailflags' => array('bounce', 'auto-reply', 'spam', 'viral'),
    -                'recipients' => array('*' => array('name', 'email', 'source'))
    -                ));
    -
    -            $supported['attachments']['*'][] = 'cid';
    +        switch ($format) {
    +            case 'email':
    +                $supported = array_merge($supported, [
    +                    'header', 'mid', 'emailId', 'to-email-id', 'ticketId', 'reply-to',
    +                    'reply-to-name', 'in-reply-to', 'references', 'thread-type', 'system_emails',
    +                    'mailflags' => ['bounce', 'auto-reply', 'spam', 'viral'],
    +                    'recipients' => ['*' => ['name', 'email', 'source']]
    +                ]);
    +                $supported['attachments']['*'][] = 'cid';
    +                break;
    +            case 'json':
    +            case 'xml':
    +                $supported = array_merge($supported, [
    +                    'duedate', 'slaId', 'staffId'
    +                ]);
    +                break;
             }
     
             return $supported;

    This patch also fixes the Unexpected data received in API request errors for duedate, slaId, and staffId used within JSON and XML payloads.

    With this being said, I have to run this by the team to see exactly what the purpose of this bit of code was and see if we can amend it to the changes in my patch.

    Disclaimer:
    Since I don't yet know the true reason behind the original code you will proceed with applying the above patch at your own risk. I cannot guarantee that this won't open your system to further issues, etc.

    Cheers.

    cherrie

    Can you change the Variable name of your custom duedate field to something else and retest? I’m thinking since it’s the same as the built-in duedate it’s rejecting it. Also, not sure why staffId is throwing an error; I’ll have to test that.

    Cheers.

    cherrie

    I know but forgot you were trying to set manual duedate with the actual field. I still need to test this so please be patient. Also, you could’ve just kept to the original thread. No need to create this duplicate.

    Cheers.

    cherrie

    I am using v1.18.1 and cannot replicate the staffId issue. If I add "staffId": 1, to my JSON payload it sets the Assignee appropriately. Not sure what's going on in your instance.

    As for the duedate issue it's due to a specific bit of code back from 1.7.x (circa 2013). To get it working you can apply the below patch:

    diff --git a/include/class.ticket.php b/include/class.ticket.php
    index a7573678..2e00fd59 100644
    --- a/include/class.ticket.php
    +++ b/include/class.ticket.php
    @@ -4370,7 +4370,7 @@ implements RestrictedAccess, Threadable, Searchable {
                 $ticket->email_id = $vars['emailId'];
     
             //Make sure the origin is staff - avoid firebug hack!
    -        if ($vars['duedate'] && !strcasecmp($origin,'staff'))
    +        if ($vars['duedate'] && in_array(strtolower($origin), ['staff', 'api']))
                 $ticket->duedate = date('Y-m-d G:i',
                     Misc::dbtime($vars['duedate']));
     
    diff --git a/include/api.tickets.php b/include/api.tickets.php
    index d160c324..bb8f7e94 100644
    --- a/include/api.tickets.php
    +++ b/include/api.tickets.php
    @@ -43,15 +43,22 @@ class TicketApiController extends ApiController {
                 foreach ($form->getFields() as $field)
                     $supported[] = $field->get('name');
     
    -        if(!strcasecmp($format, 'email')) {
    -            $supported = array_merge($supported, array('header', 'mid',
    -                'emailId', 'to-email-id', 'ticketId', 'reply-to', 'reply-to-name',
    -                'in-reply-to', 'references', 'thread-type', 'system_emails',
    -                'mailflags' => array('bounce', 'auto-reply', 'spam', 'viral'),
    -                'recipients' => array('*' => array('name', 'email', 'source'))
    -                ));
    -
    -            $supported['attachments']['*'][] = 'cid';
    +        switch ($format) {
    +            case 'email':
    +                $supported = array_merge($supported, [
    +                    'header', 'mid', 'emailId', 'to-email-id', 'ticketId', 'reply-to',
    +                    'reply-to-name', 'in-reply-to', 'references', 'thread-type', 'system_emails',
    +                    'mailflags' => ['bounce', 'auto-reply', 'spam', 'viral'],
    +                    'recipients' => ['*' => ['name', 'email', 'source']]
    +                ]);
    +                $supported['attachments']['*'][] = 'cid';
    +                break;
    +            case 'json':
    +            case 'xml':
    +                $supported = array_merge($supported, [
    +                    'duedate', 'slaId', 'staffId'
    +                ]);
    +                break;
             }
     
             return $supported;

    This patch also fixes the Unexpected data received in API request errors for duedate, slaId, and staffId used within JSON and XML payloads.

    With this being said, I have to run this by the team to see exactly what the purpose of this bit of code was and see if we can amend it to the changes in my patch.

    Disclaimer:
    Since I don't yet know the true reason behind the original code you will proceed with applying the above patch at your own risk. I cannot guarantee that this won't open your system to further issues, etc.

    Cheers.

    Even with the system error, a new ticket is being created via API and thus I'm hesitant in adding your suggested code...in case another error is generated. I'd rather leave code alone for now.

    Hopefully, this will be fixed in next version.

      cherrie

      I updated the patch above to fix the errors being logged so apply that part as well and all should be fixed.

      Cheers.

      Write a Reply...