3

How can i display all the otrs tickets using a soap api. Individual ticket can be displayed by passing ticket id in url like this:

$url = "https://url/otrs/rpc.pl"; //// URL for OTRS server
$username = "username"; //// SOAP username set in sysconfig
$password = "password"; //// SOAP password set in sysconfig
$TicketID = $_GET['id'];
  //////// Initialize new client session ////////
    $client = new SoapClient(
        null,
        array(
            'location' => $url,
            'uri' => "Core",
            'trace' => 1,
            'login' => $username,
            'password' => $password,
            'style' => SOAP_RPC,
            'use' => SOAP_ENCODED
        )
    );
//////// Create and send the SOAP Function Call ////////
    $sql =
    $TicketDetails = $client->__soapCall("Dispatch",
        array($username, $password,
            "TicketObject", "TicketGet",
            "TicketID", $TicketID,
        ));
 $ticketInfo = array();
    $i = 0;

    foreach ($TicketDetails as $name => $value){ //// explode the xml response
        if (false !== strpos($name, "s-gensym")){

            $temp[$i] = $value;
            $v = $temp[$i - 1];
            if($i % 2 != 0){
                $ticketInfo[$v] = $value;
            }
            $i++;
        }
    }
 var_dump($ticketInfo);
    exit();

How can i display all the tickets using api?????

Sujan Shrestha
  • 1,020
  • 1
  • 18
  • 32

1 Answers1

2

Use the TicketSearch API call in order to retrieve a list of Ticket IDs. Then feed this list to TicketGet as you already showed in order to retrieve ticket details.

MichielB
  • 4,181
  • 1
  • 30
  • 39
  • I did like u said. but how can i display the new and open ticket same as of otrs dashboard. Here is the code of what i have done till now. http://phpfiddle.org/main/code/wb4u-nrsj – Sujan Shrestha Jul 29 '16 at 04:39
  • 1
    I don't know what the problem is you'd still be having? You seem to loop over the results just fine. The Dashboard typically has some filter applied to the tickets, is that what you mean? Just check in the OTRS SysConfig to find those definitions. – MichielB Jul 29 '16 at 06:20
  • Could you plese help me which filters are applied to the ticket that are displayed in dashboard under new ticket table? I am really stuck here. if i use query select * from `ticket` where ticket_state_id='1' order by id DESC; it gives more result than the dashboard new ticket table. I am wondering what other filters are applied here or is there any way to get it via api. – Sujan Shrestha Jul 29 '16 at 09:41
  • The difference between the query you use and the dashboard is that the dashboard only shows new tickets in queues you have access to. Apart from that, there is a filter above the dashboard new items page where you can switch between 'All tickets', 'Tickets in My Queues', and 'My Locked Tickets'. This of course modifies the SQL query accordingly. – MichielB Jul 29 '16 at 11:21
  • how can i display the article related to the ticket id? I used ticketsearch to search the ticket ids then i used getticket to retrieve the ticket info . – Sujan Shrestha Aug 01 '16 at 08:42
  • 1
    Use the `ArticleGet()` function http://otrs.github.io/doc/api/otrs/stable/Perl/Kernel/System/Ticket/Article.pm.html - or `ArticleFirstArticle()` if you just want the first article. – MichielB Aug 01 '16 at 08:50
  • thank you... how can i link OTRS queue permission to my custom portal website?? – Sujan Shrestha Aug 01 '16 at 11:40
  • I am having problem creating ticket when i add email address to "To" field. Ticket is created but article is not created. Can you look at my code and tell me what wrong i m doing. http://phpfiddle.org/main/code/q0gx-uzsn – Sujan Shrestha Aug 04 '16 at 04:35
  • I think i am having problem in "AutoResponseType", 'auto reply', – Sujan Shrestha Aug 04 '16 at 04:41
  • How to update ticket using soap api? I am having trouble in updating owner. – Sujan Shrestha Aug 11 '16 at 04:41