OTRS RPC SOAP Problem With PHP

English! place to talk about development, programming and coding
Post Reply
MohsenGH7
Znuny newbie
Posts: 1
Joined: 08 Jul 2017, 14:58
Znuny Version: OTRS 3.3

OTRS RPC SOAP Problem With PHP

Post by MohsenGH7 »

I Want To Create An Ticket And This Is My Code:

Code: Select all

url      = "http://my_server_ip/otrs/rpc.pl";  // URL for OTRS server
$username = "root";  // SOAP username set in sysconfig
$password = "toor";  // SOAP password set in sysconfig
$typeID = 2; // id from ticket_type table
$queueID = 2; // id from queue table
$priorityID = 1; // id from ticket_priority table
$ownerID = 2; // id from users table

########################################################################
#### You don't have to change anything below here, although you can ####
########################################################################

#### FORM FIELDS ####
$title = $_GET['title'];
$from = $_GET['cust_login'];
$description = $_GET['description'];
	
#### Initialize new client session ####
$client = new SoapClient(
	null, 
	array(
		'location'  => $url,
		'uri'       => "Core",
		'trace'     => 1,
		'login'     => $username,
		'password'  => $password,
		'style'     => SOAP_RPC,
		'use'       => SOAP_ENCODED
	)
);

#### Create a new ticket shell. The function returns the Ticket ID ####
$TicketID = $client->__soapCall(
	"Dispatch", array($username, $password,
	"TicketObject", "TicketCreate", 
	"Title",        $title, 
	"TypeID",	$typeID, 
	"QueueID",   $queueID, 
	"LockID",  1, 
	"PriorityID",   $priorityID, 
	"State",        "new", 
	"CustomerUser", $from, 
	"OwnerID",      $ownerID, 
	"UserID",       1,
	)
);

##### Create an article with the info. The function returns an Article ID #### 
$email ="Test@test.com";
$ArticleID = $client->__soapCall("Dispatch",
	array($username, $password,
		"TicketObject",   "ArticleCreate",
		"TicketID",       $TicketID,
		"ArticleType",    "webrequest",
		"SenderType",     "customer",
		"HistoryType",    "WebRequestCustomer",
		"HistoryComment", "created from PHP",
		"From",           $email,
		"Subject",        $title,
		"ContentType",    "text/plain; charset=ISO-8859-1",
		"Body",           $description,
		"UserID",         1,
		"Loop",           0,
		"AutoResponseType", 'auto reply',
		"OrigHeader", array(
			'From' => $email,
			'To' => $from,
			'Subject' => $title,
			'Body' => $description
		),
	)
);

# Use the Ticket ID to retrieve the Ticket Number.
$TicketNum = $client->__soapCall("Dispatch", 
array($username, $password,
"TicketObject",   "TicketNumberLookup",
"TicketID",       $TicketID,
));

# Make sure the ticket number is not displayed in scientific notation
$big_integer = 1202400000; 
$Formatted_TicketNum = number_format($TicketNum, 0, '.', ''); 


# Print the info to the screen.
echo "<html>\n";
echo "<head>\n";
echo "<title>Ticket Successfully Submitted</title>\n";
echo "</head>\n";
echo "<body>\n";
echo "<h1>Success!</h1>\n";
echo "<p>You have successfully created ticket number $Formatted_TicketNum.</p>\n";
echo "</body>\n";
echo "</html>\n";
But This Only Return Zero.
What Is Problem Of My Code?
It Works For Ticket Get But I Cant Add Ticket.
Get Ticket :

Code: Select all

$url = "http://192.168.106.128/otrs/rpc.pl";  // URL for OTRS server
$username = "root";  // SOAP username set in sysconfig
$password = "toor";  // SOAP password set in sysconfig
$TicketID = $_GET['id'];

########################################################################
#### You don't have to change anything below here, although you can ####
########################################################################

#### Initialize new client session ####
$client = new SoapClient(
	null, 
	array(
		'location'  => $url,
		'uri'       => "Core",
		'trace'     => 1,
		'login'     => $username,
		'password'  => $password,
		'style'     => SOAP_RPC,
		'use'       => SOAP_ENCODED
	)
);

#### Create and send the SOAP Function Call ####
$TicketDetails = $client->__soapCall("Dispatch", 
array($username, $password,
"TicketObject",   "TicketGet",
"TicketID",       $TicketID,
));

####    Get the SOAP response into an array as key/value pairs     ####
#  This is kind of janky, but what it does is parse out the           #
#  detail values in the SOAP response and writes them as a key/value  #
#  pair in the $ticketInfo[] array.                                   #

$ticketInfo = array();
$i = 0;
foreach ($TicketDetails as $name => $value){ // explode the xml response
	if (false !== strpos($name, "s-gensym")){
		$temp[$i] = $value; 
		$v = $temp[$i-1]; 
		if($i % 2 != 0){ 
			$ticketInfo[$v] = $value; 
		}
		$i++;
	}
}

##############################################################################
#### The code below here is just to provide viewable proof that it worked ####
####             It can all be commented out or removed                   ####
##############################################################################
#### Return the SOAP request and response as xml-formatted text ####
/*print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n"; 
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n"; 
print "</pre>"; 

echo"<hr width='200'>";*/
// Spew out the key/value pairs from the $ticketInfo[] array
/*foreach ($ticketInfo as $name => $value){
	echo "<b>".$name.":</b> ".$value."<br>";
}*/
echo "<pre>";
print_r($ticketInfo);
echo "</pre>";
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: OTRS RPC SOAP Problem With PHP

Post by reneeb »

Can you use the GenericInterface? That has lots more debugging stuff...
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Post Reply