Creating tickets from a web form

Moderator: crythias

Locked
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Creating tickets from a web form

Post by aph »

I need to implement the following scenario:
Customers should be able to submit their request through a webpage, similar to this:
Unbenannt_164.PNG
From this information a (process) ticket should be generated in OTRS containing the information. I would like to furthermore save the information in the 'phone' field on the web form in a dynamic field, which is displayed in the process information area

Has anyone implemented something similar. What is the best way to go about it?
You do not have the required permissions to view the files attached to this post.
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Creating tickets from a web form

Post by crythias »

Note that a process ticket itself presents a Web form as an activity dialog, but if you want anything to create a process ticket, it must be provided a Process-id and and an ACTIVITY-ID.

viewtopic.php?f=53&t=30029

In order for variables to show, they must be listed in TicketZoom under ProcessManagement in SysConfig. Check the Docs.
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
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Creating tickets from a web form

Post by aph »

Thanks a lot.

I'm quite new at interface and webservices. My problem is more about how to transmit the information from the web form to OTRS to create a ticket. For example, how can I 'tell' OTRS that value in the field phone should be stored in the dynamic field 'phone'.

As references I used http://blog.otrs.org/2012/10/03/easy-ti ... interface/ and http://jeffeske.com/blog/otrs-simple-we ... using-php/. I imported the GenericTicketConnector.yml file and adjusted the otrs.SOAPRequest.pl to my enviornment (user name, queueID etc.) (both files found at https://github.com/OTRS/otrs/tree/rel-3 ... ebservices) So far I was able to create a ticket by running the otrs.SOAPRequest.pl

Now I would like to know following things:
1) How do I call the script otrs.SOAPRequest.pl on the OTRS server from the web form?
2) How can I make the contents of the created ticket dynamic? For example, at the moment the title, queue id etc. are hardcoded. I imagine I could use a variable ($queueID) so the value of queueID is not fixed, but where can I define the mapping that the value of the variable is X when the value selected in To: field of the web form is Y.
3) What is the function of GenericTicketConnector.wsdl. How is it used?

I know that not all questions are directly related to OTRS, but pointers/guides in that direction would be great
Last edited by aph on 27 Aug 2015, 15:21, edited 3 times in total.
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Creating tickets from a web form

Post by aph »

Here is my otrs.SOAPRequest.pl file

Code: Select all

#!/usr/bin/perl
# --
# otrs.SOAPRequest.pl - sample to send a SOAP request to OTRS Generic Interface Ticket Connector
# Copyright (C) 2001-2015 xxx, http://otrs.com/
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU AFFERO General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
# or see http://www.gnu.org/licenses/agpl.txt.
# --

use strict;
use warnings;

## nofilter(TidyAll::Plugin::OTRS::Perl::Dumper)

# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);

use SOAP::Lite;
use Data::Dumper;

# ---
# Variables to be defined

# this is the URL for the web service
# the format is
# <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/Webservice/<WEB_SERVICE_NAME>
# or
# <HTTP_TYPE>:://<OTRS_FQDN>/nph-genericinterface.pl/WebserviceID/<WEB_SERVICE_ID>
my $URL = 'http://localhost/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector';

# this name space should match the specified name space in the SOAP transport for the web service
my $NameSpace = 'http://www.otrs.org/TicketConnector/';

# this is operation to execute, it could be TicketCreate, TicketUpdate, TicketGet, TicketSearch
# or SessionCreate. and they must to be defined in the web service.
my $Operation = 'TicketCreate';

# this variable is used to store all the parameters to be included on a request in XML format, each
# operation has a determined set of mandatory and non mandatory parameters to work correctly, please
# check OTRS Admin Manual in order to get the complete list
my $XMLData = '
<UserLogin>xxxx</UserLogin>
<Password>xxxx</Password>
<Ticket>
    <Title>some title</Title>
    <CustomerUser>xxxx</CustomerUser>
    <QueueID>xxxx</QueueID>
    <State>Open</State>
    <TypeID>7</TypeID>
    <Priority>3 normal</Priority>
</Ticket>
<Article>
    <Subject>some subject</Subject>
    <Body>some body</Body>
    <ContentType>text/plain; charset=utf8</ContentType>
</Article>
';

# ---

# create a SOAP::Lite data structure from the provided XML data structure
my $SOAPData = SOAP::Data->type( 'xml' => $XMLData );

my $SOAPObject = SOAP::Lite->uri($NameSpace)->proxy($URL)
    ->$Operation($SOAPData);

# check for a fault in the soap code
if ( $SOAPObject->fault() ) {
    print $SOAPObject->faultcode(), " ", $SOAPObject->faultstring(), "\n";
}

# otherwise print the results
else {

    # get the XML response part from the SOAP message
    my $XMLResponse = $SOAPObject->context()->transport()->proxy()->http_response()->content();

    # deserialize response (convert it into a perl structure)
    my $Deserialized = eval {
        SOAP::Deserializer->deserialize($XMLResponse);
    };

    # remove all the headers and other not needed parts of the SOAP message
    my $Body = $Deserialized->body();

    # just output relevant data and no the operation name key (like TicketCreateResponse)
    for my $ResponseKey ( sort keys %{$Body} ) {
        print Dumper( $Body->{$ResponseKey} );    ## no critic
    }
}
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Creating tickets from a web form

Post by aph »

Here are the html and php files I'm using
HTML

Code: Select all

<html>
<head><title>Simple Web Services Form</title></head>
<body>
<h3>Simple Web Services Form</h3>
<form name='simple form' action='add_ticket.php' method='POST'>
Customer login ID: <input type='text' name='cust_login'><br>
Title: <input type='text' name='title'><br>
Description of Problem:<br>
<textarea name="description" cols="40" rows="5"></textarea><br>
<input type='submit' value='Submit' />

</form>
</body>
</html>
PHP

Code: Select all

<?PHP
error_reporting(E_ALL);
############## --  Simple web services form processor -- ###############
#                                                                      #
#         ***  OFFERED AS-IS.  USE IT AT YOUR OWN RISK!  ***           #
#                                                                      # 
#  Written by Jeff Eske - June 2012                                    #
#                                                                      #
#  Works with OTRS 3.1.6 and 3.1.7 for sure.  Probably works with      #
#  other versions as well.                                             #
#                                                                      # 
#  I don't offer support on this in any way, shape, or form.  You can  #
#  use it, but you have to figure out what to do with it.              #
#                                                                      #
#  Did I mention - USE IT AT YOUR OWN RISK!                            #
########################################################################


#######    PLEASE SET THESE VARIABLES TO MATCH YOUR SYSTEM     #########
#  You can set others in the code below, but these should be the main  #
#  things that you may want to adjust.                                 # 
########################################################################

$url      = "http://192.168.48.129/otrs/rpc.pl";  // URL for OTRS server
$username = "some_user";  // SOAP username set in sysconfig
$password = "some_pass";  // SOAP password set in sysconfig
$typeID = 7; // id from ticket_type table
$queueID = 5; // 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 = $_POST[title];
$from = $_POST[cust_login];
$description = $_POST[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 #### 
$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";

?>
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Creating tickets from a web form

Post by crythias »

aph wrote:How do I call the script otrs.SOAPRequest.pl on the OTRS server from the web form?
You probably want to push from form, not pull. Also, you can make this easier on yourself (possibly) by using email to send and setting X-OTRS-field in the header.

By push, whatever form action has been defined, any amount of code can be used to manipulate the next action. This is beyond the scope of this forum, though.
aph wrote:How can I make the contents of the created ticket dynamic? For example, at the moment the title, queue id etc. are hardcoded. I imagine I could use a variable ($queueID) so the value of queueID is not fixed, but where can I define the mapping that the value of the variable is X when the value selected in To: field of the web form is Y.
If the webform says input name="queue" and the form has received a value, the form processor (action) can send the values associated with the form fields as X-OTRS-field (X-OTRS-Queue: formfieldqueuevalue, X-OTRS-DynamicField_MyField: formfieldmyfieldvalue) or by invoker or soap XML, etc. Hopefully you know how to do this part.
aph wrote:What is the function of GenericTicketConnector.wsdl. How is it used?
https://www.google.com/search?q=wsdl
This isn't unique to OTRS.
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
aph
Znuny superhero
Posts: 646
Joined: 20 Jun 2014, 12:11
Znuny Version: 3.3.9, 4.x, 5.x

Re: Creating tickets from a web form

Post by aph »

crythias wrote:Also, you can make this easier on yourself (possibly) by using email to send and setting X-OTRS-field in the header.
I don't quite get you here. Are you suggesting that users send an e-mail to a support address, which is then fetched in OTRS? Could you elaborate please?
OTRS 3.3.x (private/testing) on Windows Server 2008 with MSSQL database.
OTRS 3.3.x (private/testing) on CentOS with MySQL database and apache
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Creating tickets from a web form

Post by crythias »

aph wrote: Are you suggesting that users send an e-mail to a support address, which is then fetched in OTRS? Could you elaborate please?
Well, that's how it usually works, but you want them to fill a form on a web page,[some magic happens], and a ticket is created.

So the magic is this: Create a web form, make an email from the input, send the email on behalf of the customer to the OTRS support email address, and let OTRS handle the rest. Note that the OTRS fields can be filled at the form-prep-for-email side by adding to the header X-OTRS-fieldname: value, exactly the same way as To: and From: are handled in the form-to-email action/processor.
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
Locked