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 OTRS Installation as Admin

– in the Menu under “Admin”->”Sysconfig” set Group to “Framework” and click “show”

– In the list of subgroups click “Core::SOAP”

– Check the boxes for SOAP::User: and SOAP::Password: and enter the values you like

– 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.

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

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 developments
$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'=&gt;$url,'uri'=&gt;"Core",'trace'=&gt;1,'login'=&gt;$user,'password'=&gt;$pass,'style'=&gt; SOAP_RPC,'use'=&gt; SOAP_ENCODED));# creating a ticket number
$ticketnr=$soapclient-&gt;__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-&gt;__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";$subject="testmessage";$articleid=$soapclient-&gt;__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,"MimeType","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 myselfuse Kernel::System::Ticket;# ... some more code$CommonObject{GroupObject}= Kernel::System::Group-&gt;new(%CommonObject);$CommonObject{QueueObject}= Kernel::System::Queue-&gt;new(%CommonObject);# you have to add this too$CommonObject{TicketObject}= Kernel::System::Ticket-&gt;new(%CommonObject);

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-&gt;new(%CommonObject);
$CommonObject{QueueObject} = Kernel::System::Queue-&gt;new(%CommonObject); # you have to add this too
$CommonObject{TicketObject} = Kernel::System::Ticket-&gt;new(%CommonObject);

what ever the things u hav said is all perfect in rpc-example.pl and rpc.pl… stii if i run the php code i get an error
“Fatal error: Uncaught SoapFault exception: [soap:Client] Application failed during request deserialization: no element found at line 1, column 0, byte -1 at /usr/lib/perl5/XML/Parser.pm line 187 in /var/www/lp/soap2.php:30 Stack trace: #0 /var/www/lp/soap2.php(30): SoapClient->__soapCall(‘Dispatch’, Array) #1 {main} thrown in /var/www/lp/soap2.php on line 30”

adminJune 22nd, 2010 at %I:%M %p

Linga: I read a forum-thread you posted in another forum, and they gave you this link

Hello I m new to using Web services like soap. I have to integrate OTRs in magento , when we enter contact us details .. that details we have to pass in OTRS to create ticket.

I have question regarding rcp.pl file.. where we have to place that file and “Dispatch” function definition – i can’t understand where this function is created.Is that function is in OTRS system or we have to create in php.

I am getting error “No operation Dispatch in WSDL”
I have used code from this link :: “http://wiki.otrs.org/index.php?title=Create_a_ticket_in_OTRS_from_PHP_via_RPC”

Awaiting for your reply… Plz help me to solve this issue.

Thanks,
Bijal Bhavsar

adminAugust 4th, 2010 at %I:%M %p

The file rpc.pl is part of otrs and is the SOAP-Interface to OTRS. It is important, that you enter the correct URL to the rpc.pl file. Perhaps you can post your php code snippet. I’m pretty sure you put a wrong URL here:

$url = “http://example.com/otrs/rpc.pl”;

This has to be replaced to the file in your OTRS-Installation

TatjanaDecember 27th, 2010 at %I:%M %p

Hello!

I am very new to OTRS and Perl as well :). I have a problem, and I cannot find any solutions for it in Internet. Sorry this question has some small relationship with the theme above.

I want to call Web-Services from OTRS (this Web-Service has to be wroten in php and has to save new customer in our own DB). I try in Kernel/Config.pm in a place where I build insert query to call this Perl script:

after that I try to add a new Customer by Customer form and get this kind of error:

Software error: Undefined subroutine &Kernel::System::CustomerUser::DB::_ConvertTo called at /opt/otrs//Kernel/Config.pm line 594.

How can I call any Web-Service FROM OTRS and give some parameters to it per Post?

Thank you very much,
Tatjana

adminDecember 28th, 2010 at %I:%M %p

Hi,

I don’t know if OTRS offers this possibility in Config.pm. If it doesn’t work, perhaps you can try inserting your code directly in the file “Kernel/System/CostumerUser.pm” in the function: CustomerUserAdd.

I have other one problem 🙂
I would like to use my own php script (webservise) that will do select, update and insert in our CustomerUser DB (I want to do so, in a case if our Customer DB will change in a time or even if it will be a simple XML file. For such DB operation I would like to use Propel, to be independet from DB structure).

With your great help I can post and request the data to and from my webservise. Now I am looikng where I can just simply globaly change CustomerUserMap or so with data from our Customer DB to have this effect. Do you think is it possible? I am looking for it, but I can not find a right place for it.
Would be great if you know and could help me.

Thank you!
Tatjana

adminJanuary 3rd, 2011 at %I:%M %p

I think the easiest thing would probably be to just sync the data into a mysql-database and use the default database Customer-User-Backend

Hello,
I am running the perl script that you posted remotely with the correct url. The script seems to call soap and post a ticket to the OTRS server, but there is something wrong. After I click on the RAW queue there is a row where the ticket is listed but all that data is missing. After I click on the ticket there is an error. What is going on?

The sample code for perl provided has some issues with integration into a bigger system due to the use of autodispatch, which while convenient is not really a great idea. This code avoids autodispatch and accomplishes the same thing in a way that can be used with other modules. In particular we found that Moose and autodispatch do not get along.

what ever the things u hav said is all perfect in rpc-example.pl and rpc.pl on windows otrs installation… but on unix i am unable to access the rpc.pl file and still if i run the php code i get an error
“Fatal error: Uncaught SoapFault exception: [soap:Client] Application failed during request deserialization: no element found at line 1, column 0, byte -1 at /usr/lib/perl5/XML/Parser.pm line 187 in /var/www/lp/soap2.php:30 Stack trace: #0 /var/www/lp/soap2.php(30): SoapClient->__soapCall(‘Dispatch’, Array) #1 {main} thrown in /var/www/lp/soap2.php on line 30″

DanilNovember 4th, 2013 at %I:%M %p

I need create ticket in otrs with attachment file. How can i get this? Thanks.