RESTful Webservices


Introduction

Create tickets using REST calls

Retrieve tickets using REST

Update tickets

Delete tickets

Retrieve lists of users and workgroups

Query tickets

Introduction

todo4teams offers a set of RESTful webservices. REST stands for Representational State Transfer, see here for an introduction.

This interface allows external applications to retrieve, search, create, modify and delete tickets.

The todo4teams RESTful services support the file-formates XML and JSON plus additionally (for some services) HTML.  The client sets the HTTP-Header-Attribute Accept (during the retrieving of data) and the Content-Type (if data are sent) and determines the relevant data format.

To test the different services you may use the programs curl or wget. In the following chapter we will show some examples with curl.

todo4teams restricts the access to the services by means of an IP-filter and/or HTTP Basic Authentication . IP filtering means that only clients with a certain known IP-address can access the relevant URLs. You can configure the list of the allowed client-systems with their IP-addresses by logging in as admin or superadmin into todo4teams. Please select the tab systems to configure the appropriate settings.

When accessing the REST-URLs It is important to use the adequate HTTP-method GET, POST, PUT or DELETE for each action (inquiry, generate, change, delete). In the examples the HTTP-method is submitted with the curl-command using the parameter X. The implementations of the REST-clients provide separate methods per HTTP method.

Please note that you can't update the tickets' state (open, locked, finished,...)! All calls will update the tickets' data without effecting the tickets' workflow.

Generate new tickets using REST

To generate a new ticket with REST you have to send a HTTP POST-Request with the following content to the URL https://<yourtodoserver>/todo4teams/rest/tasks:

{
"addressedGroupId":17,
"attachments":[{"content": [72,101,108,108,111,32,87,111,114,108,100,34,10],"filename":"attachment.txt"}],
"description":"This is my first todo",
"minutes":60,
"ownerId":7,
"priority":0,
"title":"First"
}

This JSON-Code generates a new ticket with the title "First", the description "This is my first todo", a targeting time of 60 minutes to the group with the ID 17 and the owner with the ID 7. Furthermore a file with the name "attachment.txt" will be attached to the ticket.

Set ownerId to 0 or omit this attribute to not set the ticket's owner on creation.

As the result of the action the ID of the new ticket will be returned.

You may test the service by saving the above JSON-Code to the file "ticket.json" and execute the following command:

cat ticket.json|  curl -H "Content-Type: application/json" -X POST --data-binary @- "http://yourtodoserver/ToDoServer/rest/tasks"

or if your installation requires authentication (e.g. with user 'apiuser' and password 'supersecret':

cat ticket.json|  curl -u apiuser:supersecret -H "Content-Type: application/json" -X POST --data-binary @- "http://yourtodoserver/ToDoServer/rest/tasks"

Please note that the content of the file (in the attribute "content") has to submitted as an array of byte values .

The following example automatically adds forms to the ticket and sets a few field values. Please note that the form-IDs must correspond with the form templates of your system:

{
"addressedGroupId":17,
"description":"This is my first todo",
"forms":[
 {
"id":41,
"fields":
  {"Straße_t":"",
 "Name":"Meier",
 "Vorname":"Max",
  }
 },
 {
"id":42,
"fields":{
   "DeviceID" : "54354325435"
  }
 }
],
"minutes":480,
"ownerId":7,
"priority":0,
"title":"The title!"
}

The scheduled  end time will be set  according to the attribute minutes.

If you should prefer the XML-formate instead of JSON, please use the following example as a template to generate a ticket:

This example generates an supplemented file and attach it to the form.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<task>
<addressedGroupId>17</addressedGroupId>
<description>This is my first todo</description>
<forms>
 <form>
  <id>41</id>
  <fields>
   <entry>
    <key>Name_t</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">Meier</value>
   </entry>
  </fields>
 </form>
</forms>
<minutes>300</minutes>
<ownerId>7</ownerId>
<priority>0</priority>
<title>The XML Title</title>
</task>

For a further test you may use the following command that saves the XML-Code to the file "ticket.xml":

cat ticket.xml|  curl -H "Content-Type: application/xml" -X POST --data-binary @- "http://yourtodoserver/ToDoServer/rest/tasks"

Note that we changed the content type to application/xml. The service will return something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<id>22232</id>

Retrieving single tickets

You can get access to a single ticket by reading out the URL of the kind  https://yourtodoserver/todo4teams/rest/tasks/<ticketid>, for example http://yourtodoserver/ToDoServer/rest/tasks/14515 with the GET-Request.

You can test this request also in the browser of your choice, the ticket will be displayed as HTML.

Requesting JSON format ...

curl -u apiuser:supersecret  -o out.json -H "Accept: application/json" -X GET   "https://yourtodoserver/todo4teams/rest/tasks/22217"

the result might look like this:

{
"addressedGroupId": 110,
"assignedUserId": 0,
"attachments": [
  {
  "content": [72,101,...10],
  "filename": "test.txt"
  }
 ],
"creationDate": "2025-01-28 10:29",
"description": "hello",
"forms": [],
"id": 22217,
"minutes": -16,
"ownerId": 223,
"priority": 0,
"properties": {
 "AuthUserId": "226"
 },
"scheduledEndDate": "2025-01-28 14:36",
"status": 0,
"title": "TEST"
}

In XML-formate this call may look like:

curl -o out.xml -H "Accept: application/xml" -X GET   "https://yourtodoserver/todo4teams/rest/tasks/22217"

The result may look like this in XML-formate:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<task>
<addressedGroupId>110</addressedGroupId>
<assignedUserId>0</assignedUserId>
<attachments>
 <attachment>
  <content>SGVsbG8gV29ybGQhCg==</content>
  <filename>test.txt</filename>
 </attachment>
</attachments>
<creationDate>2025-01-28 10:29</creationDate>
<description>hello</description>
<forms />
<id>22217</id>
<minutes>234</minutes>
<ownerId>223</ownerId>
<priority>0</priority>
<properties>
 <entry>
  <key>AuthUserId</key>
  <value>226</value>
 </entry>
</properties>
<scheduledEndDate>2025-01-28 14:36</scheduledEndDate>
<status>0</status>
<title>TEST</title>
</task>

Updating tickets

In order to update the status of a ticket on the server, you cand send the modified XML- or JSON-representation via PUT-Request to the URL of the ticket, e.g.  https://yourtodoserver/todo4teams/rest/tasks/22217. Please note that you have to use the corresponding content-type as in the following examples:

This is the JSON data to be send. We will save it to a file named ticket.json.

{
"addressedGroupId": 110,
"minutes": 10,
"ownerId": 0,
"priority": 2,
"title": "This ticket was updated by a REST service call."
}

Update of the ticket 14519 with the ticket.json saved as JSON-formate:

cat ticket.json|  curl -H "Content-Type: application/json" -X PUT --data-binary @- "https://yourtodoserver/todo4teams/rest/tasks/22217"

Update of the ticket 22217 with the ticket.xml saved as XML-formate:

cat ticket.xml|  curl -H "Content-Type: application/xml" -X PUT --data-binary @- "http://yourtodoserver/todo4teams/rest/tasks/22217" 

Please note:

  • To change the targeting time of a ticket, please use the element minutes. A change of the elements creationDate, startDate, endDate and scheduledEndDate will not be submitted.
  • You are allowed to update tickets in all states (open, locked, finished,...). Preferably update tickets while in state 'open'. Use the GET method (see above) to check a ticket's state before updating!
  • Forms and attachments will be exactly submitted as you have sent via REST: If you delete an attachment in the REST-representation and want to update the ticket, the attachment will be deleted from the ticket on the server. The same is also valid for forms.
  • Omit the attributes ownerId and addressedGroupId (or assign 0) if you don't want to change these values.

Deleting tickets

You can delete tickets with a HTTP-DELETE-request to the URL of the tickets, for example:

curl -i -H "Accept: application/json" -X DELETE "https://yourtodoserver/todo4teams/rest/tasks/22217"

Note: Calls to delete or update tickets will result in a server side exception if the ticket id in the URL is invalid!

Searching tickets via REST calls

There is a possibility to perform a flexible search for certain tickets by sending a request to the URL http://localhost:8080/ToDoServer/rest/query?q=...

As result you will receive a list of all ticket-representation as JSON- or XML-files.

The HTTP-parameter q contains the the search pattern by matters of a SQL-where-expresssion. Please note that you have to use this parameter in an URL-coded manner.

So if  you want to search a ticket that contains the word "Meier" and it's ID should be bigger than 14,000, the query may look like: t.id>14000 and t.title like '%Meier%'

URL-coded this will be equivalent to the parameter q with the values t.title+like+%27%25Meier%25%27 and the following query:

curl  -H "Accept: application/json" -H "Content-Type: application/json" -X GET   "https://yourtodoserver/todo4teams/rest/query?q=t.id%3E14000+and+t.title+like+%27%25Meier%25%27&limit=1000&withAttachments=true"

Use the alias 't' for the ticket object, e.g. t.id for the id attribute or t.title for the title.

With help of the optional parameter limit you can define the maximum amount of hits. The parameter withAttachments=true can suppress the attachment-elements. The use of this parameter withAttachments=true is especially convenient if you make an inquiry of a large number of tickets. Otherwise it is possible that the amount of submitted data will exceed several hunderts megabytes.

A query result in JSON format might look like this:

image-20250128155557-2.png

Retrieving the user- and group-list

You can make a search to the list of all users and groups of the todo4teams application with REST. Please use the URLs http://yourtodoserver/ToDoServer/rest/users or http://yourtodoserver/ToDoServer/rest/workgroups with the Accept-Type application/xml or application/json as in the following examples:

Retrieving the list of users
curl  -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET   "https://yourtodoserver/todo4teams/rest/users"

curl  -H "Accept: application/json" -H "Content-Type: application/json" -X GET   "https://yourtodoserver/todo4teams/rest/users"
Retrieving the list of groups
curl  -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET   "http://localhost:8080/ToDoServer/rest/workgroups"

curl  -H "Accept: application/json" -H "Content-Type: application/json" -X GET   "http://localhost:8080/ToDoServer/rest/workgroups"