Hi all,

 

I'm writing some code in PHP at the moment to get one of our other
systems in the organisation to talk to OTRS via the SOAP API interface.
I'm adapting the code example I found at
http://www.mail-archive.com/otrs@otrs.org/msg27452.html (which didn't
work when I originally tried it).

 

What I'm trying to achieve is for our staff to use the other system to
create scheduled outage notifications to our services, which through a
bunch of other ways works out what services are affected and who to tell
about it.  It will then send out the notifications to our customers by
using the API to create tickets in OTRS and then link these tickets to a
master (or parent) ticket which is our internal ticket for tracking the
outage.

 

I'm now at the stage where I can use the API to create a ticket number,
lookup an otrs userid, create a ticket, and add an article to it - all
of that works without issue.  What I can't seem to do at the moment,
though, is link tickets together.  I've checked the API spec (I'm using
OTRS 2.4.4) and believe I'm covering the bases.  I notice from reading
another email on this list that the property "Direction" isn't listed on
dev.otrs.org, and wonder if maybe there's other hidden stuff like that
that may be getting in my way?  I'll post the code below - can anyone
suggest why I might not be able to do linking in this way?  I've done my
reading and think I've doing it right.

 

Here's the code I'm currently using.  It doesn't return any errors (or,
at least none I've seen):

 

function otrsinject($in_title, $in_subject, $in_to, $in_owner,
$in_customerid, $in_customeruser, $in_message) {

              $otrs_title = $in_title;

              $otrs_subject = $in_subject;

              $otrs_queue = $Queue;

              $otrs_from = "x...@yyy.com";

              $otrs_email = $in_to;

              $otrs_user = "xxx";

              $otrs_pass = "xxx";

              $otrs_url = "http://xxx/otrs/rpc.pl";;

              $otrs_queue = "Sched. Events";

 

              $otrs_customerid = $in_customerid;

              $otrs_customeruser = $in_customeruser;

              $otrs_message = $in_message;

 

              $soapclient = new SoapClient(null, array('location'  =>
$otrs_url,

                                      'uri'       => "Core",

                                      'trace'     => 1,

                                      'login'     => $otrs_user,

                                      'password'  => $otrs_pass,

                                      'style'     => SOAP_RPC,

                                      'use'       => SOAP_ENCODED));

              

              # creating a ticket number

              $ticketnr = $soapclient->__soapCall("Dispatch",
array($otrs_user, $otrs_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

 

              $otrs_userid = $soapclient->__soapCall("Dispatch",
array($otrs_user, $otrs_pass, "UserObject", "UserLookup",

 
"UserLogin", $in_owner

 
));

              

              $ticketid = $soapclient->__soapCall("Dispatch",
array($otrs_user, $otrs_pass, "TicketObject", "TicketCreate",

 
"TN", $ticketnr,

 
"Title", $otrs_title,

 
"Queue", $otrs_queue,

 
"Lock" , "unlock",

 
"PriorityID", 3,

 
"State" , "new",

 
"CustomerId", $in_customerid, 

 
"CustomerUser", $in_customeruser,

 
"OwnerID",     $otrs_userid,

 
"UserID", $otrs_userid

                                                                     ));

 

              $articleid = $soapclient->__soapCall("Dispatch",
array($otrs_user, $otrs_pass, "TicketObject", "ArticleSend",

                                         "TicketID"         , $ticketid,

                                         "ArticleType"      ,
"email-external",  # email-external|email-internal|phone|fax|...

                                         "SenderType"       , "agent", #
agent|system|customer

                                         "From"             ,
$otrs_from,

                                         "To"               ,
$otrs_email,

                                         "Subject"          ,
"[Ticket#".$ticketnr."] ".$otrs_subject,

                                         "Body"             ,
$otrs_message,

                                         "ContentType"      ,
"text/plain; charset=utf-8",

                                         "Charset"          , "utf-8",

                                         "HistoryType"      ,
"EmailCustomer", #
EmailCustomer|Move|AddNote|PriorityUpdate|WebRequestCustomer|...

                                         "HistoryComment"   , "generated
by OTRSInterface-Class",

                                         "UserID"           ,
$otrs_userid,

                                         "NoAgentNotify"    , 1, # if
you don't want to send agent notifications

                                         "MimeType"             ,
"text/plain",

                                         "Loop"             , 0 # auto
reject|auto follow up|auto follow up|auto remove

                                         ));

                                         

              $linkid = $soapclient->__soapCall("Dispatch",
array($otrs_user, $otrs_pass, "LinkObject", "LinkAdd",

 
"SourceObject", "Ticket",

 
"SourceKey", "0601158",  #0601158 is the tn of a pre-existing ticket to
link to.

 
"TargetObject", "Ticket",

 
"TargetKey" , $ticketid,

 
"Type", "ParentChild",

 
"Direction", "Target",

 
"State" , "Valid",

 
"UserId", $otrs_userid

                                                                     ));

              return $ticketid;

}

 

I hope someone may shed some light, or that someone looking to do
something similar in php might be able to use the above code.

 

Kind Regards,

James Morgan

---------------------------------------------------------------------
OTRS mailing list: otrs - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/otrs
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/otrs

NEW! ENTERPRISE SUBSCRIPTION - Get more information NOW!
http://www.otrs.com/en/support/enterprise-subscription/

Reply via email to