Warm tip: This article is reproduced from serverfault.com, please click

OTRS ticket create in custom portal using soap api

发布于 2016-07-10 06:22:57

Has any one tried creating OTRS tickets in thier own custom website using api? I am really stucked in this. Any reference, documentation and help would be much appreciated.

Questioner
Sujan Shrestha
Viewed
0
Sujan Shrestha 2016-07-10 17:39:30

I found the answer. Hope this will help you guys.

$url      = "https://your-server/otrs/rpc.pl";  // URL for OTRS server
$username = "username";  // SOAP username set in sysconfig
$password = "password";  // SOAP password set in sysconfig

(GO to admin panel and select sysconfig, then framework in dropdown and select core::soap)

$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


// Form Fields(Your Ticket 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'];


/// 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",    "webrequest",
        "SenderType",     "customer",
        "HistoryType",    "WebRequestCustomer",
        "HistoryComment", "created from PHP",
        "From",           $username,
        "Subject",        $title,
        "ContentType",    "text/plain; charset=ISO-8859-1",
        "Body",           $description,
        "UserID",         1,
        "Loop",           0,
        "AutoResponseType", 'auto reply',
        "OrigHeader", array(
        'From' => $username,
        'To' => 'Postmaster',
        '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";