Per SOAP mit OTRS kommunizieren

English! place to talk about development, programming and coding
Post Reply
TheoFontane
Znuny newbie
Posts: 9
Joined: 26 Feb 2009, 17:03

Per SOAP mit OTRS kommunizieren

Post by TheoFontane »

Hallo zusammen,

ich plane, unser OTRS-System (mit Erweiterung von CAPE IT) per SOAP anzusprechen, um ticketbezogene Daten auf Wunsch abzufragen.

Leider finde ich weder in der OTRS-Admin-Doku, noch in der OTRS-Developer-Doku, noch in der CAPE-IT-Doku auch nur einen Hinweis, wie das funktionieren soll. Ich habe ein paar Foreneinträge gesehen, wonach man die Perl-Schnittstelle "SOAP:LITE" benötigen soll.

Bitte, gibt es irgendwo im Netz eine Dokumentation, bei der halbwegs ausführlich beschrieben ist,
a) welche Module man dazu bei OTRS installieren muss
b) welche Schritte notwendig sind, damit diese Module funktionieren
c) wie man sich an diese Schnittstelle verbindet?

Ich bin für jeden Hinweis dankbar. Mit Perl habe ich noch so gut wie gar keine Erfahrungen gemacht. Ist dieses Vorhaben machbar?

Danke im Voraus
Theo
Mobios
Znuny advanced
Posts: 108
Joined: 29 Feb 2008, 16:30
Znuny Version: 3.x 4.x 5.x 6.x
Real Name: Oliver Oltmanns
Company: i-cron
Location: Köln
Contact:

Per SOAP mit OTRS kommunizieren

Post by Mobios »

schließe mich meinem Vorredner an.
Suche ebenfalls vergeblich nach einer Soap Doku, vllt. sogar mit Anwenderbeispiele.
i-cron OTRS IT-Service Management
https://i-cron.de
Invader
Znuny newbie
Posts: 28
Joined: 04 Mar 2009, 16:16
Znuny Version: 2.34

Per SOAP mit OTRS kommunizieren

Post by Invader »

Also Doku findet ihr unter:
http://dev.otrs.org/2.3/Kernel/System/Ticket.html

Auf dem OTRS System müsst ihr das Perl Modul SOAP::Lite installieren. Auf dem PHP System braucht ihr das PHP SOAP Extension (aktiviert natürlich).

Dann in OTRS einen Benutzer und ein Passwort festlegen - und mit folgenden PHP Code sample solltet ihr den Zugriff auch hinbekommen:

Code: Select all

<?PHP
echo "<title>Test SOAP-Schnittstelle</title>";
echo "<h2>Test SOAP-Schnittstelle von OTRS</h2>";

echo "<pre>";
$client = new SoapClient(null, array('location'  => "http://localhost/otrs/rpc.pl",
                                     'uri'       => "Core",
                                     'trace'     => 1,
                                     'login'     => "user",
                                     'password'  => "passwort",
                                     'style'     => SOAP_RPC,
                                     'use'       => SOAP_ENCODED));

try {
$result = $client->__soapCall("Dispatch", array("user", "passwort", "TicketObject", "ArticleGet", "TicketID", 11));
} catch (SoapFault $fault) {
  echo "REQUEST:\n".$client->__getLastRequest()."\n";
  echo "RESPONSE:\n".$client->__getLastResponse()."\n";
  echo "</pre>";
  exit;
}
echo "REQUEST:\n".$client->__getLastRequest()."\n";
echo "RESPONSE:\n".$client->__getLastResponse()."\n\n";
echo "Response Array:<br>";
var_dump($result);
echo "</pre>";

?>
Der Code holt über die SOAP-Schnittstelle von ORTS alle Daten zum Ticket mit der TicketID = 11 und alle Artikel, die diesem Ticket zugeordnet sind. Die erhaltenen Daten werden in einem Array abgespeichert. Nicht vergessen die richtige URL anzugeben (http://localhost/otrs/rpc.pl)... geht nur wenn das PHP Skript auf dem OTRS System ausgeführt wird :)

Ein leeres Ticket würdet ihr so anelgen:

Code: Select all

$ticket = $client->__soapCall("Dispatch", array("user", "passwort", "TicketObject", "TicketCreate",
        "TN"            , $ticketnumber,
        "Title"         , 'Some Ticket Title',
        "Queue"         , 'Raw',
        "Lock"          , 'unlock',
        "Priority"      , '3 normal',
        "State"         , 'new',
        "Type"          , 'default',
        "Service"       , '',
        "SLA"           , '',
        "CustomerID"    , '',
        "CustomerUser"  , 'customer@example.com',
        "OwnerID"       , 1,
        "ResponsibleID" , 1,
        "UserID"        , 1
));
Dabei könnt ihr auf die ganz oben verlinkte Doku zurückgreifen, dort ist der Systax für die einzelnen Aktionen hinterlegt.
Mobios
Znuny advanced
Posts: 108
Joined: 29 Feb 2008, 16:30
Znuny Version: 3.x 4.x 5.x 6.x
Real Name: Oliver Oltmanns
Company: i-cron
Location: Köln
Contact:

Per SOAP mit OTRS kommunizieren

Post by Mobios »

Vielen Dank, für den Ansatz. Es sind ja recht wenig Informationen hierüber im Netz und auch hier im Forum zu finden, bzw, Anfragen blieben unbeantwortet.
Das hat mir schon ein wenig weiter geholfen :)

Grüße,

Mobios
i-cron OTRS IT-Service Management
https://i-cron.de
TheoFontane
Znuny newbie
Posts: 9
Joined: 26 Feb 2009, 17:03

Per SOAP mit OTRS kommunizieren

Post by TheoFontane »

Ja, vielen Dank für die Hinweise. Sobald ich endlich wieder Zeit dafür finde, schreibe ich ein Feedback, was man noch hätte schreiben können (um es anfängerfreundlich zu gestalten).

Super - so macht ein Forum Spaß.
Mobios
Znuny advanced
Posts: 108
Joined: 29 Feb 2008, 16:30
Znuny Version: 3.x 4.x 5.x 6.x
Real Name: Oliver Oltmanns
Company: i-cron
Location: Köln
Contact:

Per SOAP mit OTRS kommunizieren

Post by Mobios »

Freue mich drauf

Grüße,

Mobios
i-cron OTRS IT-Service Management
https://i-cron.de
dbluemer
Znuny newbie
Posts: 3
Joined: 25 Mar 2009, 14:31
Znuny Version: 2.3.4

Per SOAP mit OTRS kommunizieren

Post by dbluemer »

Hallo,
ich bin mir nicht sicher, ob ich da was Grundsätzliches falsch mache, aber bei mir führt das Skript (meiner Umgebung angepasst natürlich) immer dazu, dass ich NULL als Rückgabe bekomme. Ist das ein Symptom für ein spezielles, vielleicht bekanntes, Problem bzw. Fehler?
dbluemer
Znuny newbie
Posts: 3
Joined: 25 Mar 2009, 14:31
Znuny Version: 2.3.4

Per SOAP mit OTRS kommunizieren

Post by dbluemer »

Hallo nochmal,
mein geschildertes Problem hat sich inzwischen erledigt.

Eine andere Frage habe ich aber noch:
Der Dispatcher der rpc.pl bietet standardmäßig eine Menge von Klassen an, deren Methoden aufgerufen werden können. Mir fehlen da entsprechende Handler für die Klassen State und CustomerUser. Diese habe ich einfach selbst hinzugefügt und der Zugriff funktioniert auch problemlos. Meine Frage ist, ob es einen bestimmten Grund gibt, weshalb diese Klassen standardmäßig nicht per SOAP angesprochen werden können. Muss ich befürchten, dass diese Schnittstellen in zukünftigen Versionen nicht mehr funktionieren?


Gruß

Dennis
Mobios
Znuny advanced
Posts: 108
Joined: 29 Feb 2008, 16:30
Znuny Version: 3.x 4.x 5.x 6.x
Real Name: Oliver Oltmanns
Company: i-cron
Location: Köln
Contact:

Per SOAP mit OTRS kommunizieren

Post by Mobios »

dbluemer wrote:Hallo nochmal,
mein geschildertes Problem hat sich inzwischen erledigt.
Das ist schön. Fein für das Forum wären natürlich auch Angaben, wie du das gelöst hast. :)
i-cron OTRS IT-Service Management
https://i-cron.de
dbluemer
Znuny newbie
Posts: 3
Joined: 25 Mar 2009, 14:31
Znuny Version: 2.3.4

Per SOAP mit OTRS kommunizieren

Post by dbluemer »

Hallo,
nun da keiner antwortete, dachte ich, es interessiert keinen.

Aber gut: Der SOAP User musste innerhalb von OTRS noch freigeschaltet werden. Eine aussagekräftige Fehlermeldung oder einfach eine gute Doku wären echt hilfreich gewesen...vielleicht gibt es diese ja, ich kenne sie nicht.
jgk
Znuny newbie
Posts: 1
Joined: 09 Apr 2009, 09:10
Znuny Version: 2.3.4

Per SOAP mit OTRS kommunizieren

Post by jgk »

Hallo zusammen,

Erstmal danke für diesen Thread. Der hat mich um Lichtjahre weiter voran gebracht.
Ich habe mir mal die Mühe gemacht die ganze OTRS-SOAP Geschichte etwas zusammen zu fassen. Vielleicht nützt es dem ein oder anderen ja was.

Ist auf englisch. Falls es jemand unbedingt auf deutsch braucht übersetze ich es auch gerne.

http://www.iniy.org/?p=20

Viele Grüße
jgk
Invader
Znuny newbie
Posts: 28
Joined: 04 Mar 2009, 16:16
Znuny Version: 2.34

Per SOAP mit OTRS kommunizieren

Post by Invader »

Vielleicht noch wichtig als Hinweis:

Beim php Skript sollte man die jeweilige SOAP Transaktion auf Erfolg prüfen. Um ein Ticket zu erstellen muss man ja sagen wir 3 SOAP Transaktionen ausführen. Geht die 3. schief, habt ihr im OTRS ein kaputtes Ticket liegen. Also solltet ihr bei das Skript bei Misserfolg entsprechend automatisch aufräumen lassen. Ich hab da jetzt leider kein Beispiel Skript zur Hand ;)
Mobios
Znuny advanced
Posts: 108
Joined: 29 Feb 2008, 16:30
Znuny Version: 3.x 4.x 5.x 6.x
Real Name: Oliver Oltmanns
Company: i-cron
Location: Köln
Contact:

Per SOAP mit OTRS kommunizieren

Post by Mobios »

Großartig,
haben sich ja doch noch einiges an Hilfestellung zusammen getragen. Ich war einmal so frei und habe deinen Artikel von http://www.iniy.org/?p=20 hier reinkopiert, damit man diesen in der Suche finden kann und damit die Info zusammenbleibt.
jgk wrote: OTRS Soap Interface
Disclaimer: This are my first trys with the Soap Interface. If you’ve got better information just send it to me or post a comment, I will gladly update this
documentation. I just wrote this article because there is almost no information about the OTRS Soap-Interface on the web. Perhaps it helps someone.
At first it is necessary to set the Soap user and password:
- Login into your existing 1. OTRS Installation as Admin
2. - in the Menu under “Admin”->”Sysconfig” set Group to “Framework” and click “show”
3. - In the list of subgroups click “Core::SOAP”
4. - Check the boxes for SOAP::User: and SOAP::Password: and enter the values you like
5. - click update
Now you can use the OTRS Functions over SOAP.
At my test installation the Setting of the username and password over the admin-interface didn’t work at all. I had to enter it manually in the rpc.pl, but
normally I think it should work.
You find a documentation of the OTRS-Modules/Functions you can use here:
http://dev.otrs.org/
The invocation of a Module/Function works like follows:
$RPC->Dispatch($User, $Pw, 'Module','Function', Parameter);
A good start is the rpc-example.pl, which you find in the folder scripts of your OTRS-Install. I modified the example a bit to create a ticket. No guarantee
that this doesn’t crash your database, so don’t try on a live system.
scripts/rpc-example.pl
use SOAP::Lite('autodispatch', proxy => 'http://localhost/otrs/rpc.pl');
my $User = 'exampleuser';
my $Pw = 'examplepass';
my $RPC = Core->new();
# create a new ticket number
my $TicketNumber = $RPC->Dispatch($User, $Pw, 'TicketObject','TicketCreateNumber');
print "RPC: New Ticketnumer created: ".$TicketNumber."\n";
my $TicketId = $RPC->Dispatch($User, $Pw, 'TicketObject', 'TicketCreate',
TN => $TicketNumber,
Title => 'Test Ticket',
Queue => 'Raw', # or QueueID => 123,
Lock => 'unlock',
PriorityID => 2, # or PriorityID => 2,
State => 'open', # or StateID => 5,
CustomerUser => 'customer at example.com',
OwnerID => 1, # new owner
ResponsibleID => 1, # new responsible
UserID => 1,
);
print "RPC: New Ticket id is: $TicketId\n";
my $ArticleID =$RPC->Dispatch($User, $Pw, 'TicketObject', 'ArticleSend',
TicketID => $TicketId,
ArticleType => 'email-external', # email-external|email-internal|phone|fax|...
SenderType => 'agent', # agent|system|customer
From => 'root', # not required but useful
To => 'customer', # not required but useful
Cc => '', # not required but useful
ReplyTo => '', # not required
Subject => 'Test Ticket', # required
Body => "Test Body", # required
MessageID => '', # not required but useful
Charset => 'ISO-8859-15',
HistoryType => 'EmailCustomer', # EmailCustomer|Move|AddNote|PriorityUpdate|WebRequestCustome
HistoryComment => 'Some free text!',
UserID => 1,
NoAgentNotify => 0, # if you don't want to send agent notifications
Type => 'text/plain',
Loop => 0, # auto reject|auto follow up|auto follow up|auto remove
);
Of course this works in PHP too. The task i wanted to do is send an e-mail to a user and simultaneously create a ticket in otrs. This is the ticket creation
process in otrs:
create a new ticketnumber
create a new ticket with that number
attach a message (called article) to the ticket, which at once is sent out per mail
iniy.org » Blog Archive » OTRS Soap Interface http://www.iniy.org/?p=20
1 von 4 14.05.2009 17:19
Of course the last step can vary. if you don’t want to send an e-mail for example.
# WARNING: This could destroy your OTRS-Database, please use only for testing and as a starting point for your own development
$user = "testuser";
$pass = "testpass";
$url = "http://localhost/otrs/rpc.pl" # replace with your own otrs url
# initialising soap client
$soapclient = new SoapClient(null, array('location' => $url,
'uri' => "Core",
'trace' => 1,
'login' => $user,
'password' => $pass,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED));
# creating a ticket number
$ticketnr = $soapclient->__soapCall("Dispatch", array($user, $pass, "TicketObject", "TicketCreateNumber"));
#php changes long numbers to 123E+10 notation to prevent this screwing up our ticketnumbers we convert notation
#it into normal plain numbers. but only if not string, because sometimes you have a string addition like XY123 on your
#ticket numbers
if(! is_string($ticketnr) ) $ticketnr = number_format($ticketnr,0, '.', '');
# create the new ticket
$title = "some test title";
$queue = "support";
$customerid = "1234567";
$customeruser = "John Doe";
$userid = 3; # your OTRS-Userid, varies of course in every installation
$ticketid = $soapclient->__soapCall("Dispatch", array($user, $pass, "TicketObject", "TicketCreate",
"TN", $ticketnr,
"Title", "[ Ticket#: ".$ticketnr." ] ".$title,
"Queue", $queue,
"Lock" , "unlock",
"PriorityID", 5,
"State" , "closed successful",
"CustomerId", $customerid,
"CustomerUser", $customeruser,
"OwnerID" , $userid,
"UserID", $userid
));
#create the new e-mail message, which is send out and attached to the ticket automatically
$from = "support@example.com";
$to = "janedoe@example.com";
$message = "pay your bills";
$articleid = $soapclient->__soapCall("Dispatch", array($user, $pass, "TicketObject", "ArticleSend",
"TicketID" , $ticketid,
"ArticleType" , "email-external",
"SenderType" , "agent",
"From" , $from,
"To" , $to,
"ReplyTo" , "",
"Subject" , "[ Ticket#: ".$ticketnr." ] ".$subject,
"Body" , $message,
"ContentType" , "text/plain; charset=utf-8",
"Charset" , "utf-8",
"HistoryType" , "EmailCustomer",
"HistoryComment" , "generated by OTRSInterface-Class",
"UserID" , $userid,
"NoAgentNotify" , 0,
"Type" , "text/plain",
"Loop" , 0
));
Of course this is just a very basic example. You can really use any OTRS-Class over the SOAP-Interface, just read the API. I realized, that some of the
Objects are not created correctly in rpc.pl. So just add the additonal ones you need:
use Kernel::System::Group;
use Kernel::System::Queue; # this one I added by myself
use Kernel::System::Ticket;
# ... some more code
$CommonObject{GroupObject} = Kernel::System::Group->new(%CommonObject);
$CommonObject{QueueObject} = Kernel::System::Queue->new(%CommonObject); # you have to add this too
$CommonObject{TicketObject} = Kernel::System::Ticket->new(%CommonObject);
i-cron OTRS IT-Service Management
https://i-cron.de
Post Reply