Create Ticket Using Soap Api PHP

Moderator: crythias

Post Reply
szn0007
Znuny newbie
Posts: 28
Joined: 10 Jul 2016, 08:59
Znuny Version: 3.1.12
Real Name: Sujan Shrestha
Company: Classictech

Create Ticket Using Soap Api PHP

Post by szn0007 »

I have done the hard part. I am stuck in one problem i.e Auto Reply of the Ticket to the customer. Ticket Generates fine but auto reply is not going to the customer. I am using OTRS 3.1.12. Here is my code.
if(isset($_POST['submit']))
{
$url = "https://otrs.classic.com.np/otrs/rpc.pl"; // URL for OTRS server
$username = "username"; // SOAP username set in sysconfig
$password = "password"; // 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 = 1; // id from users table


### Form Fields
$username = $_POST['username_id'];
$queueID = $_POST['queue'];
$issue_type = $_POST['issue_type'];
$subject = $_POST['subject'];
$title = $username.'-Issue With'.' '.$issue_type.' -'.$subject;
$description = $_POST['description'];
$category = $_POST['category'];
$priorityID = $_POST['priority'];
$to = $_POST['to'];

#### 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", $username,
"OwnerID", $ownerID,
"UserID", 1,
)
);

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


)
);


# 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"; */

echo "<script>alert('You have successfully created ticket number $Formatted_TicketNum.')</script>";



}
?>
Post Reply