OTRS SOAP API

How to access OTRS SOAP API in PHP

Tagged:

Answers

  • <?php
    
    function create_ticket($mail_sub, $mail_to, $mail_BCC, $mail_from, $mail_body, $otrs_reff = array()) {
    	$url	  	= "https://my.host.com/otrs/rpc.pl";
    	$username 	= "OTRS_SOAP_user";
    	$password 	= "password";
    
    	$TicketNr 	= (isset($otrs_reff['TicketNr']) && !empty($otrs_reff['TicketNr'])) ? $otrs_reff['TicketNr'] : null;
    	$TicketID	= (isset($otrs_reff['TicketID']) && !empty($otrs_reff['TicketID'])) ? $otrs_reff['TicketID'] : null;
    	$ArticleID	= null;
    
    	global $num;
    	global $name;
    
    	# Set up a new SOAP connection:
    	$client = new SoapClient(null, array(
    		'location' => $url,
    		'uri' => "Core",
    		'trace' => 1,
    		'login' => $username,
    		'password' => $password,
    		'style' => SOAP_RPC,
    		'use' => SOAP_ENCODED)
    	);
    
    	if($TicketNr && $TicketID){
    		$TicketNr = $client->__soapCall("Dispatch",
    			array($username, $password,
    				"TicketObject", "TicketNumberLookup",
    				"TicketID", $TicketID,
    			)
    		);
    
    		if(!$TicketNr){
    			$TicketID = null;
    		}
    	}
    
    	if(!$TicketNr && !$TicketID){
    		$TicketCreateNumber = $client->__soapCall("Dispatch",
    		array(
    			$username, $password, 
    			"TicketObject", 
    			"TicketCreateNumber"
    		));
    
    		if(! is_string($TicketCreateNumber) )
    			$TicketNr = number_format($TicketCreateNumber,0, '.', '');
    
    		if($TicketNr){
    			$TicketID = $client->__soapCall("Dispatch",
    				array($username, $password,
    					"TicketObject", "TicketCreate",
    					"TN", $TicketNr,
    					"Title", $mail_sub,
    					"Queue", "Eurus|NOC",
    					"Lock" , "unlock",
    					"PriorityID", 3,
    					"State" , "open",
    					"CustomerID", $mail_from,
    					"CustomerUser", $mail_from,
    					"OwnerID", 1,
    					"UserID", 1
    				)
    			);
    		}
    	}
    
    	if($TicketNr && $TicketID){
    		$ArticleID = $client->__soapCall("Dispatch",
    			array($username, $password,
    				"TicketObject", "ArticleSend",
    				"TicketID", $TicketID,
    				"ArticleType", "email-external",
    				"SenderType", "agent",
    				"From", $mail_from,
    				"To", $mail_to,
    				"Bcc", $mail_BCC,
    				"Subject", '[Ticket#'.$TicketNr.'] '.$mail_sub,
    				"ContentType", "text/html; charset=utf-8",
    				"Charset", "utf-8",
    				"HistoryType", "EmailCustomer",
    				"HistoryComment", "generated by SPAM CALLS ALERT",
    				"Body", $mail_body,
    				"UserID", 1,
    				"NoAgentNotify", 0,
    				"MimeType", "text/html",
    				"Loop", 0
    			)
    		);
    	}
    
    	return array(
    		"TicketNr" => $TicketNr,
    		"TicketID" => $TicketID,
    		"ArticleID" => $ArticleID
    	);	
    }
    ?>
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!