OTRS – Simple Web Service Example Using PHP

OTRS,Web Services,Web Stuff — Jeff Eske on July 27, 2012 at 10:54 am

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. 


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 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 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:


#  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


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 –


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


  1. […] UPDATE:  I’ve now created sample files and posted a quick run-through on what’s needed to use them. […]

  2. […] UPDATE:  I’ve now created sample files and posted a quick run-through on what’s needed to use them. […]

  3. It’s worth to mention, that you set the Username and Password at http://host/otrs/index.pl?Action=AdminSysConfig;Subaction=Edit;SysConfigSubGroup=Core::SOAP;SysConfigGroup=Framework;#
    Thanks for the walk-through!

    Comment by Tomasz — August 30, 2012 @ 8:10 am
  4. Tomasz,

    Thanks. I have a short comment next to the username and password in the file, but should make that clearer.


    Comment by Jeff Eske — August 30, 2012 @ 10:53 am
  5. […] It’s still very much a work-in-progress.  Currently, it’s “read-only”.  I’m in the process of adding two-way functionality, utilizing OTRS web services. […]

    Pingback by OTRS – Mobile Front-end « — February 22, 2013 @ 9:44 am
  6. […] Continuing on with my studies of OTRS web services, I’ve created a page that will pull an OTRS ticket back when supplied with the ticket’s ID via GET.  Basically, you give the page the ticket ID via the URL – http://webserver/get_ticket.php?id=xx. I’ve included a complete ticketGet zip file at the end.  In addition to this example, I have another post explaining how to submit a ticket via web services. […]

  7. […] with some basic web service functions included by default.  I’ve already done a post about using web services to create a new ticket via TicketCreate(), as well as a post about retrieving an existing ticket via TicketGet().  I’ve also created a […]

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. | Jeff's Blog