Home » Php » DIsplay OTRS 5 articleid using soap api (ArticleIndex function)

DIsplay OTRS 5 articleid using soap api (ArticleIndex function)

Posted by: admin October 29, 2018 Leave a comment

Questions:

currently i develop search system for otrs using soap api, basiccaly, i have already success return ticket id and ticket details, but now i am having problem to get article list based on the ticket id, below is the code for method article_index:

    public function article_index($ticket_id, $params = array())
{
    if (is_null($ticket_id)) {
        return null;
    }
    $params['TicketID'] = $ticket_id;
    $params['DynamicFields'] = "1";

    $result = $this->dispatch_call("ArticleIndex", $params);
    if (is_array($result)) {
        return self::object_to_hash($result);
    } else {
        return null;
    }
}

    private function dispatch_call($endpoint, $params)
{
    $soap_params = array();
    $soap_params[] = new SoapParam($this->username, $this->login_type);
    if (!is_null($this->password)) {
        $soap_params[] = new SoapParam($this->password, "Password");
    }
    foreach ($params as $key => $value) {
        $soap_params[] = new SoapParam($value, $key);
    }
    //$soap_params[] = array('trace' => '1');

    try {
        $client = new \SoapClient(null, array(
            'location' => $this->base_url . '/nph-genericinterface.pl/Webservice/' . $this->webservice,
            'uri' => $this->namespace,
            'trace' => 1,
            'style' => SOAP_RPC,
            'use' => SOAP_ENCODED,
            'stream_context'=> stream_context_create(array('ssl'=> array('verify_peer'=>false,'verify_peer_name'=>false)))
        ));

        $result = $client->__soapCall($endpoint, $soap_params);
        // echo "Response:\n" . $client->__getLastResponse() . "\n";
        unset($client);
        return $result;
    } catch (SoapFault $fault) {
        //echo "Response:\n" . $client->__getLastResponse() . "\n";
        unset($client);
        return null;
    }
}
private static function object_to_hash($obj)
{
    $arr = array();
    $arr_obj = is_object($obj) ? get_object_vars($obj) : $obj;
    foreach ($arr_obj as $key => $value) {
        $value = (is_array($value) || is_object($value)) ? self::object_to_hash($value) : $value;
        $arr[$key] = $value;
    }
    return $arr;
}

below is the code of function to call article_index method

    $data = raw_searcharticle($id);
function raw_searcharticle($id){
    $otrs = new Otrs();
    $message = "";
    try {

                if(is_array($id) ){
                    $message .= "not a single result";
                }else{
                    if($id == ''){
                        $message .= "Ticket not found";
                    }else{
                        $article_get = $otrs->article_index($id);
                        (array)$message = $article_get;
                    }
                }
        } catch (\Exception $e) {
            (array)$message = $e;
    }
    return $message;
}

the problem is, the result always return:

{ array(2)[“faultcode”]=> string(6) “Server” [“faultstring”]=> string(21) “Got
no OperationType!” }

i really dont have any idea whats wrong wiith the code.
thanks in advance

Answers: