[SOLVED] Create Ticket using rpc.pl

Moderator: crythias

Locked
skullz
Znuny superhero
Posts: 658
Joined: 24 Feb 2012, 03:58
Znuny Version: LTS and Features
Real Name: Mo Azfar
Location: Kuala Lumpur, MY
Contact:

[SOLVED] Create Ticket using rpc.pl

Post by skullz »

Hi all..
i managed to get a php code from somewhere/somebody from this forum as i remember..Credits to them..
This php code will create a tickect via soap (rpc.pl)..
How do i put the dynamic field in the script??For example i have 'CustomerName' as dynamic field (ticket)

Code: Select all

<?php

echo "<title>OTRS SOAP - Create Ticket</title>";
echo "<h2>OTRS SOAP - Create Ticket</h2>";

echo "<pre>";

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Subject: <input type="text" name="subject" required/><br/>
Report: <input type="text" name="body" required/><br/>
Name: <input type="text" name="name" required/><br/>
Email: <input type="email" name="email" required/><br/>

<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />   
   </form>    

<?php
if(isset($_POST['submit'])) // GET INPUT FROM USER WHEN USER CLICK SUBMIT 
{

$subject = $_POST['subject'];
$body = $_POST['body'];
$name = $_POST['name'];
$email = $_POST['email'];

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

try {

$ticketnumber = $client->__soapCall("Dispatch", array("otrs", "otrs", "TicketObject", "TicketCreateNumber"));

if(! is_string($ticketnumber) ) $ticketnumber = number_format($ticketnumber,0, '.', '');

echo "TicketNumber: ".$ticketnumber."<br>";

$ticket = $client->__soapCall("Dispatch", array("otrs", "otrs", "TicketObject", "TicketCreate",
    "TN"            , $ticketnumber,
    "Title"         , 'External Ticket',
    "Queue"         , 'Raw',
    "Lock"          , 'unlock',
    "Priority"      , '3 normal',
    "State"         , 'new',
    "Type"          , 'default',
    "Service"       , '',
    "SLA"           , '',
    "CustomerID"    , $email,
    "CustomerUser"  , $name,
	"OwnerID"       , 1,
    "ResponsibleID" , 1,
    "UserID"        , 1
));

$article = $client->__soapCall("Dispatch", array("otrs", "otrs", "TicketObject", "ArticleCreate",
    "TicketID"         , $ticket,
    "ArticleType"      , 'email-external',
    "SenderType"       , 'customer',
    "From"             , $email,
    "To"               , 'otrs@localhost',
    "Cc"               , '',
    "ReplyTo"          , '',
    "Subject"          , $subject,
    "Body"             , $body,
	"MessageID"        , '',
    "ContentType"      , 'text/plain; charset=utf-8',
    "HistoryType"      , 'WebRequestCustomer',
    "HistoryComment"   , 'WebRequestCustomer',
    "UserID"           , 1,
    "NoAgentNotify"    , 1,
    "AutoResponseType" , '',
    "ForceNotificationToUserID" , 1
));



} 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($ticket);
//var_dump($article);


} //closing if submit
echo "</pre>";
?> 
Last edited by skullz on 04 Jan 2013, 14:14, edited 1 time in total.
My Github
OTRS CE/LTS Discord Channel
Cant Update Package Anymore ? Check This

Professional OTRS, Znuny & OTOBO services: efflux.de/en
Free and premium add-ons: English
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Create Ticket using rpc.pl

Post by crythias »

Try searching the forum about this.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
skullz
Znuny superhero
Posts: 658
Joined: 24 Feb 2012, 03:58
Znuny Version: LTS and Features
Real Name: Mo Azfar
Location: Kuala Lumpur, MY
Contact:

Re: [SOLVED] Create Ticket using rpc.pl

Post by skullz »

I managed to get a PHP code from somewhere/somebody from this forum as i remember..
Credits to them..using "nph-genericinterface.pl" :D :D
Not only for create ticket, also for getticket operation.
My Github
OTRS CE/LTS Discord Channel
Cant Update Package Anymore ? Check This

Professional OTRS, Znuny & OTOBO services: efflux.de/en
Free and premium add-ons: English
tchtam
Znuny newbie
Posts: 3
Joined: 31 Dec 2012, 23:48
Znuny Version: 3.1.11
Real Name: Thomas Tam
Company: CANARIE Inc.

Re: [SOLVED] Create Ticket using rpc.pl

Post by tchtam »

Hi, I wonder you can share what you have done with ticketget. I have been trying for a few days now but no luck. I posted my issue on Jan 1, so far no one reply.

Perhaps, I did something wrong. I could try your script whether I could make it work on my system.

Thanks
skullz
Znuny superhero
Posts: 658
Joined: 24 Feb 2012, 03:58
Znuny Version: LTS and Features
Real Name: Mo Azfar
Location: Kuala Lumpur, MY
Contact:

Re: [SOLVED] Create Ticket using rpc.pl

Post by skullz »

tchtam wrote:Hi, I wonder you can share what you have done with ticketget. I have been trying for a few days now but no luck. I posted my issue on Jan 1, so far no one reply.

Perhaps, I did something wrong. I could try your script whether I could make it work on my system.

Thanks
I already look at your topic..
here my script..but im using PHP language.

Code: Select all

<?php
//Create Webservice in OTRS First!!
//verify that the Perl module SOAP::Lite is installed

//Configure php.ini (IN PHP DIRECTORY), enable soap_dll extension by uncomment "extension=php_soap.dll"  
error_reporting(E_ALL);
?>

<html>
<head>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<label for="TD">Ticket ID:</label>
<input type="text" name="tid" required/><br/>

<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />   
</form>    
</body>
</html>

<?php
if(isset($_POST['submit'])) // GET INPUT FROM USER WHEN USER CLICK SUBMIT 
{
function objectToArray($d) {
		if (is_object($d)) {
			$d = get_object_vars($d);
		}
 
		if (is_array($d)) {
			return array_map(__FUNCTION__, $d);
		}
		else {
			return $d;
		}
	}
 
$url = 'http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector/';
$tid = $_POST['tid'];

try {
   $client = new SoapClient(null, array('location'  => $url,
                                        'uri'       => 'http://www.otrs.org/TicketConnector/',      // make sure it's the same as the namespace in network config of the webservice
                                        'trace'     => true,
                                        'style'     => SOAP_RPC,
                                        'use'       => SOAP_ENCODED));
} catch (Exception $e) {
   echo "<h2>Exception Error!</h2>";
   echo $e->getMessage();
}

//var_dump($client);

$Operation = 'TicketGet';
try {
   $TicketID = $client->__soapCall($Operation, array(

      new SoapParam("root@localhost", "UserLogin"),
      new SoapParam("root", "Password"),
	  new SoapParam($tid, "TicketID"),
	  new SoapParam("1", "DynamicFields")    
		 
));
} catch (SoapFault $fault) {
   echo "REQUEST:\n".$client->__getLastRequest()."\n";
   echo "RESPONSE:\n".$client->__getLastResponse()."\n";
   exit;
}
//var_dump($TicketID);
$array = objectToArray($TicketID);
print_r($array);

	echo "<br/><br/>Ticket ID: ".$tid."<br/>";
	echo "Ticket Number: ".$array['TicketNumber']."<br/>";
	echo "Ticket Queue: ".$array['Queue']."<br/>";
	echo "Ticket Owner: ".$array['Owner']."<br/>";
	echo "Ticket State: ".$array['State']."<br/>";
	echo "Ticket Type: ".$array['Type']."<br/>";
	echo "Ticket Age: ".$rray['Age']."<br/>";
	echo "Ticket Age2: ".gmdate ('H:i:s', $array['Age'])."<br/>";
//echo "\n RESPONSE:\n".$client->__getLastResponse()."\n";

} //closing if submit

?> 
Here my webservice config

Code: Select all

---
Debugger:
  DebugThreshold: debug
  TestMode: 0
Description: Ticket Connector Sample
FrameworkVersion: 3.1.11
Provider:
  Operation:
    SessionCreate:
      Description: Creates a Session
      MappingInbound: {}
      MappingOutbound: {}
      Type: Session::SessionCreate
    TicketCreate:
      Description: Creates a Ticket
      MappingInbound:
        Type: Simple
      MappingOutbound:
        Type: Simple
      Type: Ticket::TicketCreate
    TicketGet:
      Description: Retrieve Ticket data
      MappingInbound:
        Type: Simple
      MappingOutbound:
        Type: Simple
      Type: Ticket::TicketGet
    TicketSearch:
      Description: Search for Tickets
      MappingInbound:
        Config:
          KeyMapDefault:
            MapTo: ''
            MapType: Keep
          ValueMapDefault:
            MapTo: ''
            MapType: Keep
        Type: Simple
      MappingOutbound:
        Type: Simple
      Type: Ticket::TicketSearch
    TicketUpdate:
      Description: Updates a Ticket
      MappingInbound:
        Type: Simple
      MappingOutbound:
        Type: Simple
      Type: Ticket::TicketUpdate
  Transport:
    Config:
      MaxLength: 100000000
      NameSpace: http://www.otrs.org/TicketConnector/
    Type: HTTP::SOAP
RemoteSystem: ''
Requester:
  Transport:
    Type: HTTP::SOAP
My Github
OTRS CE/LTS Discord Channel
Cant Update Package Anymore ? Check This

Professional OTRS, Znuny & OTOBO services: efflux.de/en
Free and premium add-ons: English
Locked