OTRS – Simple Web Service Example Using PHP

Posted on July 27, 2012

UPDATED:  I’ve changed employers and have moved on to other projects.  I no longer use OTRS, or have access to OTRS, so I won’t really be able to help you beyond what I’ve already posted here. 

Jeff

A fair amount of my traffic seems to be people looking for information about using web services in OTRS.  I’ve written a couple of entries about this in the past.  One covers changes in the services from 3.1.2 to 3.1.4.  In the other entry, I briefly described how easy it is to create tickets via web services.  This time around, I’ll provide a basic example of how to actually create a ticket via web services, using PHP to make the TicketCreate() SOAP request.  I’m in the process of integrating this into a mobile front-end for OTRS.

UPDATE: 2013-2-25 – I’ve just tested this with version 3.2.1 and it still works, as is.

UPDATE: 2013-3-5 – I’ve added a post describing how to use the OTRS TicketGet() SOAP function also.

I’ve created a zip file that contains two files.

form.html
form.html is a VERY basic html page that has a form on it.  There are only 3 fields in the form – Customer Login ID, Title, Description.  You could very easily add, or even remove, fields in the form to allow more, or less, control by the end user.

add_ticket.php
add_ticket.php actually does the heavy lifting.  There’s a section towards the top where you’ll need to set some variables to match your implementation of OTRS.  I’ve commented the code, but I’ll go over the variable part below.

Here’s the section of add_ticket.php that will need to be updated to your specifics:

[CODE]

#######    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://your_otrs_server/otrs/rpc.pl”;  // URL for OTRS server
$username = “SOAPusername”;  // SOAP username set in sysconfig
$password = “SOAPpassword”;  // 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

[/CODE]

The first 3 – $url, $username, $password, are all pretty simple.  As the comment in the example above notes, and as Tomasz pointed out in his comment, you will need to set the SOAP username and password in the OTRS Admin interface at –

http://server/otrs/index.pl?Action=AdminSysConfig;Subaction=Edit;SysConfigSubGroup=Core::SOAP;SysConfigGroup=Framework;#

One thing to remember on the URL is that if you are using SSL on your server, you’ll need to change from http:// to https://.  The other 4 – $typeID, $queueID, $priorityID, and $ownerID,  will all need to be changed to ids from your system.

I use MySQL Query Browser to pull back this info but, due to the way OTRS works, you can gather that info directly from the application.  For instance, to find the id for the user that you want to use as the default owner, you can simply go in as an Admin and goto Admin > Agents.  Once you have the list of Agents, simply mouse over the Agent that you’d like to use.  When you mouse over, you should see the URL in the Status Bar of the browser.  If you look at the URL – https://otrs_server/otrs/index.pl?Action=AdminUser;Subaction=Change;UserID=2;Search=, you’ll see UserID=some number (bolded in the example).  This number is the id that you need.  Same with the other values.  You should be able to find places within OTRS with links to the things that you need.  Within the URLS, there will be an id=number.  That number should be the value that you need.

If you understand PHP, forms, and form processing, it’s really easy to expand the usefulness of forms.  Some examples would be:

1> Add form fields to collect specific information from the customer that is necessary for solving the problem but isn’t readily available otherwise.  You then take those bits and pieces and combine them into the description, via the add_ticket page.  This can get you a more complete description of the problem than possible with a simple text box where the customer is responsible for trying to figure out what needs to be added.

2> Add a Type dropdown to the form and pass that id over to add_ticket.  That would allow the customer to indicate if it was a failure, request, etc.

3> Add a Priority dropdown to the form and pass the id.  That would allow the customer to indicate what they think the priority is.  In my experience, most will mark it as High Priority, no matter how mundane the issue…

Generally, in my experience, the less choices that you give to the customer, the better off you are.

Anyway, have fun.

Jeff Eske

================================
Download the zip file – Simple Web Services example

Leave a Comment

If you would like to make a comment, please fill out the form below.

You must be logged in to post a comment.

© Copyright Jeff's Blog • Powered by Wordpress • Using Detour theme created by Brian Gardner.