OTRS Soap Webservice

Hilfe zu Znuny Problemen aller Art
Locked
nailuj
Znuny newbie
Posts: 3
Joined: 08 Apr 2013, 11:06
Znuny Version: 3.2.2

OTRS Soap Webservice

Post by nailuj »

Hallo liebes OtterHub Team,
ich habe versucht ein OTRS Webservice zu erstellen und diesen mit PHP anzusprechen.
Ich möchte dies nicht über rpc.pl machen, da das ja so wie ich gelesen habe out of date ist und nicht mehr weiterentwickelt wird.
Ich finde aber fast nur tutorials die mit rpc.pl arbeiten.

Ich habe einen User angelegt der Zugriff auf Queues hat.

Die Konfiguration des Webservices ist folgende:

Code: Select all

---
Debugger:
  DebugThreshold: debug
  TestMode: 0
Description: OTRS Anbindung an den Webservice
FrameworkVersion: 3.2.2
Provider:
  Operation:
    SessionCreate:
      Description: ''
      MappingInbound: {}
      MappingOutbound: {}
      Type: Session::SessionCreate
    TicketCreate:
      Description: ''
      MappingInbound: {}
      MappingOutbound: {}
      Type: Ticket::TicketCreate
    TicketGet:
      Description: ''
      MappingInbound: {}
      MappingOutbound: {}
      Type: Ticket::TicketGet
    TicketSearch:
      Description: ''
      MappingInbound: {}
      MappingOutbound: {}
      Type: Ticket::TicketSearch
  Transport:
    Config:
      MaxLength: 10000000
      NameSpace: urn:otrs-com:soap:functions
    Type: HTTP::SOAP
RemoteSystem: webservice.otrsurl.de
Requester:
  Invoker: {}
  Transport:
    Config:
      Authentication:
        Password: '*******'
        Type: BasicAuth
        User: otrs
      Encoding: utf-8
      Endpoint: http://www.example.com:8080/endpoint
      NameSpace: http://www.example.com/actions
      SOAPAction: Yes
      SOAPActionSeparator: '#'
    Type: HTTP::SOAP
Das ist ein Ausschnitt meins PHP Code:

$arr_soap_client = array(
'location' => $this->url,
'uri' => "Core",
'connection_timeout' => 5,
'trace' => 1,
'exceptions' => 1,
'login' => $this->wslogin_user,
'password' => $this->wslogin_pass,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED
);

$this->otrs = new SoapClient(null, $arr_soap_client) or die("faild to create Object");

$param_array = array(
new SoapParam($user_queue, 'UserLogin'),
new SoapParam($user_pass, 'Password')
);

$this->session = $this->otrs->__soapCall('SessionCreate', $param_array); (Line 76)

Schon das anlegen der Session schlägt in php fehl:
client_otrs->CreateSession() #3 /var/www/html/dev/test.php(90): otrs_mail->__construct() #4 {main} thrown in /var/www/html/dev/class/client-otrs.class.php on line 76

Line 90 in der test.php ist der Klassenaufruf der client-otrs.class.php aufruft. Line 76 ist die oben abgebildete Zeile.

Wenn ich dann aber ins Log schaue vom OTRS Webservice sieht alles ok aus:
Output:
$VAR1 = {
'SessionID' => '10befc521e4baa1ca1d6782d0729c7f247'
};

Ich versteh nicht genau was ich falsch mache. Hat jemand ein Tutorial dazu, das sich nicht auf rpc bezieht?
jojo
Znuny guru
Posts: 15020
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: OTRS Soap Webservice

Post by jojo »

Hallo,

schau Dir mal das Perl basierte Beispiel hier an: http://blog.otrs.org/2012/10/03/easy-ti ... interface/

Am besten Du lädst Dir für die Definition des Webservices das yml und das WSDL File hier runter: https://github.com/OTRS/otrs/tree/rel-3 ... ebservices
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
nailuj
Znuny newbie
Posts: 3
Joined: 08 Apr 2013, 11:06
Znuny Version: 3.2.2

Re: OTRS Soap Webservice

Post by nailuj »

Hallo,
danke für die Info, hab ich mir angeschaut. Hat mir aber nicht geholfen, es scheinte ein größeres Problem zu sein.
Ich habe ein Testserver auf dem hat mein php script ohne Probleme funktioniert. Nur auf dem Livesystem nicht. Ich habe dann gedacht es muss ja dann an der OTRS Installation liegen. Dann habe ich vom Livesystem die Dateien zum Testsystem rüberkopiert und die selbe Datenbank verbunden. Und das Testsystem ging immer noch ohne Probleme, dann habe ich beschlossen das es an irgendetwas größerem liegen muss und das System neu installiert. Beim direktaufruf mit dem Browser der URL hat sich die Antwort schon unterschieden- Beim Aufruf von http://otrs_url.de/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector/ auf dem Testsystem bekam ich "Length Required" als Antwort und beim Livesystem direkt einen Fehler: "Fehler 324 (net::ERR_EMPTY_RESPONSE): Server hat die Verbindung geschlossen. Es wurden keine Daten gesendet."

Jetzt habe ich ein kleines neues Problem. Ich kann pro OTRS Verbindung immer nur eine Funktion ausführen. Wenn ich die zweite aufrufe bekomme ich den selben Fehler mit den Headers wie oben.
Wenn ich am Anfang von jeder Funktion ein connect und am Ende ein disconnect mache dann funktioniert das (siehe code). Das ist aber ja sicher nicht so gewollt.
Ich habe hier mal eine php Datei zusammengestellt die bei euch so sofort funktionieren sollte.

Code: Select all

<?php

class client_otrs 
{            
	var $otrs;
	var $url;
	var $wslogin_user;
	var $wslogin_pass;
	var $user_queue;
	var $user_pass;
	var $session;
	private $arr_soap_client;
	
	function __construct()
	{

                $this->user_queue = "OTRS_USER";
		$this->user_pass = "OTRS_PW";
		$this->url  = "http://OTRS_URL/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector/";

		$this->arr_soap_client = array(
			'location'	=> $this->url,
			'uri'		=> "Core", 
			'connection_timeout' => 5, 
			'trace'		=> 1,
			'exceptions'	=> 1, 
			'style'		=> SOAP_RPC,
			'use'		=> SOAP_ENCODED
		    );
                
                $this->otrs = new SoapClient(null, $this->arr_soap_client) or die("faild to create Object");
	}

	function connect()
	{

		try
		{
			$this->otrs = new SoapClient(null, $this->arr_soap_client) or die("faild to create Object");
		}
		catch (SoapFault $e) 
		{
                        $this->test();
			//throw new SoapFault("OTRS-01","ERROR! SOAP RESPONSE: ".$e->getMessage());
		}



	}
	
	function disconnect()
	{
		unset($this->otrs);
	}
	
	function CreateSession()
	{
		$this->connect();
		try
		{
			$param_array = array(
				new SoapParam($this->user_queue, 'UserLogin'),
				new SoapParam($this->user_pass, 'Password')
			);
                        
			$this->session = $this->otrs->__soapCall('SessionCreate', $param_array);

		}
		catch (SoapFault $e) 
		{	
			$this->test();
			//throw new SoapFault("OTRS-02","ERROR! SOAP RESPONSE: ".$e->getMessage());
		}

		$this->disconnect();
	}
	
	function __destruct() 
	{
		$this->disconnect();
	}
	
	function TicketSearch($subject,$body)
	{
                
		$this->connect();
		try
		{
		$param_array = array(
			new SoapParam($this->session, 'SessionID'),
                    	//new SoapParam($this->user_queue, 'UserLogin'),
			//new SoapParam($this->user_pass, 'Password'),
			new SoapParam($subject,'Subject'),
			new SoapParam($body, 'Body')
		);
		
		$TicketSearch = $this->otrs->__soapCall('TicketSearch', $param_array);
                error_log("TicketSearch: ".json_encode($TicketSearch));
                
			return $TicketSearch;
		}
		catch (SoapFault $e) 
		{
						$this->test();
                        //throw new SoapFault("OTRS-03","ERROR! SOAP RESPONSE: ".json_encode($e));
		}
		$this->disconnect();
	}

	function CreateTicket($arr_attr_ticket="",$arr_attr_article="")
	{
		$this->connect();
		try 
		{
				$param_array = array(
					//new SoapParam($this->user_queue, 'UserLogin'),
					//new SoapParam($this->user_pass, 'Password'),
					new SoapParam($this->session, 'SessionID'),
                                    
				    );
				
				if ($arr_attr_ticket!="")
				{
					$param_array[] = new SoapParam($arr_attr_ticket,'Ticket');
				}
				if ($arr_attr_article!="")
				{
					$param_array[] = new SoapParam($arr_attr_article,'Article');
				}
			    
			    
			$TicketID = $this->otrs->__soapCall('TicketCreate', $param_array);
			return $TicketID;
		}
		catch (SoapFault $e) 
		{
                        $this->test();
			//throw new SoapFault("OTRS-04","ERROR! SOAP RESPONSE: ".json_encode($e)); //$e->getMessage());
		}
		$this->disconnect();
	}

	function UpdateTicket($ticketID,$arr_attr_ticket="",$arr_attr_article="")
	{

		$this->connect();
		try 
		{
			$param_array = array(
				//new SoapParam($this->user_queue, 'UserLogin'),
				//new SoapParam($this->user_pass, 'Password'),
				new SoapParam($this->session, 'SessionID'),
				new SoapParam($ticketID,'TicketID')
			    );
			
			if ($arr_attr_ticket!="")
			{
				$param_array[] = new SoapParam($arr_attr_ticket,'Ticket');
			}
			if ($arr_attr_article!="")
			{
				$param_array[] = new SoapParam($arr_attr_article,'Article');
			}
			
			//return $param_array;
			
			$TicketID = $this->otrs->__soapCall('TicketCreate', $param_array);
			return $TicketID;
		}
		catch (SoapFault $e) 
		{
                       $this->test();
			//throw new SoapFault("OTRS-04","ERROR! SOAP RESPONSE: ".$e->getMessage());
		}
		$this->disconnect();
	}
	
	
	function get_ticket($ticketnumber)
	{
		$this->connect();
		try 
		{
			//$this->session="102a78fe03d9cb54618b004495894651d6";
			$param_array = array(
					//new SoapParam($this->user_queue, "UserLogin"),
					//new SoapParam($this->user_pass, "Password"),
					new SoapParam($this->session, 'SessionID'),
					new SoapParam($ticketnumber, 'TicketID')
				    );
			/*$param_array = array(
					//new SoapParam($this->user, "UserLogin"),
					//new SoapParam($this->pass, "Password"),
					'SessionID'=>$this->session,
					'TicketID'=>$ticketnumber
				    );
			*/

			$getTicket = $this->otrs->__soapCall('TicketGet', $param_array);
			return $getTicket;
		}
		catch (SoapFault $e) 
		{
                        $this->test();
			//throw new SoapFault("OTRS-05","ERROR! SOAP RESPONSE: ".$e->getMessage());
		}
                $this->disconnect();
	}
	
	function test()
	{
		echo "<hr>getLastRequestHeaders: ";
		print_r(htmlentities($this->otrs->__getLastRequestHeaders()));
		echo "<hr>getLastRequest: ";
		print_r(htmlentities($this->otrs->__getLastRequest()));
		echo "<hr>";
		echo "<hr>getLastResponseHeaders: ";
		print_r(htmlentities($this->otrs->__getLastResponseHeaders()));
		echo "<hr>getLastResponse: ";
		print_r(htmlentities($this->otrs->__getLastResponse()));
	}
	
	public function otrs($subject, $body, $customerFrom, $customerID, $queue, $articleType)
        {
                $otrs = new client_otrs();
                $otrs->CreateSession();
                $Ticket_nr=$otrs->TicketSearch($subject, $body);

                $arr_ticket=array(
                    "StateID"=>'1',
                    "Title"=>$subject,
                    "Queue"=>$queue,
                    "CustomerUser"=>$customerFrom,
                    "CustomerID"=>$customerID,
                    "PriorityID"=>3
                    );

               
                $arr_article=array(
                    "Subject"=>$subject,
                    "Body"=>$body,
                    "ContentType" => 'text/plain; charset=utf8',
                    "ArticleType" => $articleType
                    );

                 echo json_encode($Ticket_nr);
                 
                if ($Ticket_nr!="")
                {
                        $ticket=$otrs->get_ticket($Ticket_nr);
                        print_r($ticket);

                        if ($ticket->StateID!='1' and $ticket->StateID!='4')
                        {
                                $arr_ticket["StateID"]='2';
                                $arr_article["Subject"]="Open";
                                $arr_article["Body"]="Webservice-OTRS-Ticket wurde erneut geöffnet";
                                $arr_article["ArticleType"]="SendAgentNotification";
                                $arr_article["HistoryType"]="AddNote";

                                echo json_encode($otrs->UpdateTicket($Ticket_nr,$arr_ticket,$arr_article));
                        }
                }
                else
                {
                        echo json_encode($otrs->CreateTicket($arr_ticket,$arr_article));
                }



        }

	

}

// $subject, $body, $customerFrom, $customerID, $queue, $ArticleType
$otrs = new client_otrs();
echo $otrs->otrs("Hallo Welt2", "Hier ist das erste Testticket", "customerFrom", "customerID", "queue","email-external");

?>
Als weitere Frage, ich möchte an Personen ein Ticket schicken, die noch kein Kunde bei OTRS sind. Das Problem ist nur das ich zu dem Zeitpunkt den Vor und Nachnamen nicht im System habe. Da ich die User Persönlich ansprechen möchte, würde ich diese gerne übergeben. Hat dazu jemand eine Idee?

Dankeschön im Vorraus :-)
nailuj
Znuny newbie
Posts: 3
Joined: 08 Apr 2013, 11:06
Znuny Version: 3.2.2

Re: OTRS Soap Webservice

Post by nailuj »

hat niemand eine idee?
Locked