Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

API Features Beyond Create Ticket

Hello,

Wondering if there are any API features provided besides the "create ticket" feature. I need the ability to integrate with a couple other systems - essentially, I need to be able to show lists of tickets in another app and allow for links into OSTicket.

Does OSTicket provide such API integrations? If not, does anybody know of any plugins that might do the same?

Thanks
Scott

Comments

  • Heya,

    The only built in api function at the moment is to create tickets.

    I've been contemplating making a pull request for some more API functions that could be used.

    Would something like this work?
    It'll create a json array with all the ticket data that you specify in the link.

    This will give you the id (can be used to generate the link), when it was created, the number of the ticket and the subject.
    It will also check if the created date starts with 2017.

    Pretty much all data is available, just need to write the right syntax.

    The following filters are available: exact, isnull, gt, gte, lt, lte, contains, startswith, hasbit

    <?php
    @chdir(dirname(__FILE__).'/'); //Change dir.
    require('api.inc.php');

    if (!osTicket::is_cli())
    die(__('tickets.php only supports local calls'));

    require_once(INCLUDE_DIR.'class.ticket.php');

    function isFilter($var){
    $index = strrpos($var, '_');
    if(!$index || index == strlen($var) - 1)
    return false;

    $last_word = substr($var, $index + 1);
    return in_array($last_word, array('exact', 'isnull', 'gt', 'gte', 'lt', 'lte', 'contains', 'startswith', 'hasbit'));
    }

    $tickets = Ticket::objects();
    foreach ($_GET as $key => $value) {
    if(isFilter($key)){
    if(isset($_GET[$key]))
    $tickets->filter(array($key=>$value));
    } else {
    $tickets->values($key);
    }
    }

    if ($tickets->exists(true)) {
    $result = array();
    foreach ($tickets as $T)
    array_push($result, $T);
    echo json_encode($result);
    } else {
    echo json_encode(array('Errorcode' => 2, 'Message' => 'No tickets found.'));
    }
    ?>
  • Thanks for this - being a lazy developer, I was hoping a full-featured RESTful API was already available/built-in (or someone had created a plugin). 

    But this is definitely a start...
  • Micke1101 not a dev for this project, and is a forum user that is trying to help you.
  • edited June 13
    My lazy side just connects directly to the database.. 

    ie: 

    SELECT t.ticket_id, fev.value as subject, t.isoverdue, t.created, MAX(tt.created) as last, s.firstname, s.lastname,
                COUNT(te.id) as messages,
                d.name, sla.name as sla

                FROM ot_ticket t
                LEFT JOIN ot_staff s ON s.staff_id = t.staff_id
                LEFT JOIN ot_thread tt ON tt.object_id = t.ticket_id
                LEFT JOIN ot_thread_entry te ON tt.id = te.thread_id
                LEFT JOIN ot_department d ON d.id = t.dept_id
    LEFT JOIN ot_sla sla ON sla.id = t.sla_id
                LEFT JOIN ot_form_entry fe ON fe.object_id = t.ticket_id 
                LEFT JOIN ot_form_entry_values fev ON fev.entry_id = fe.id

                WHERE t.status_id=1 AND d.manager_id = 38

                GROUP BY t.ticket_id
                ORDER BY t.ticket_id DESC

    Get all tickets for that manager.. useful for preparing a ticket status report for each manager.
Sign In or Register to comment.