RESTful Webservices


Version 5.0 and all following versions of  todo4teams do support webservices in REST-format. REST is Representational State Transfer, see here for an introduction.

This interface allows external applications to retrieve, search, create and modify 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 a IP-filter. This 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.

It is important during accessing the REST-URLs 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.

Generate new tickets with REST

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

{
"addressedGroupId":17,
"attachments":[{"content":"am9v","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.

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

You may test the service by saving the 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"

Please note that the content of the file (in the attribute "content") has to submitted as base64-coded.

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 targeting time will be displayed  corresponding to the changing of tickets via REST-call with the element minutes in 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>
<attachments>
 <attachment>
  <content>am9v</content>
  <filename>jee3</filename>
 </attachment>
</attachments>
<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"

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   "http://yourtodoserver/ToDoServer/rest/users"

curl  -H "Accept: application/json" -H "Content-Type: application/json" -X GET   "http://yourtodoserver/ToDoServer/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"

Retrieving single tickets

You can get access to a single ticket by reading out the URL of the kind  http://yourtodoserver/ToDoServer/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 in HTML-formate.

In XML-formate this call may look like:

curl -o out.xml -H "Accept: application/xml" -X GET   "http://yourtodoserver/ToDoServer/rest/tasks/14515"

The result may look like this in XML-formate:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<task>
<addressedGroupId>17</addressedGroupId>
<attachments>
 <attachment>
  <content>am9v</content>
  <filename>jee3</filename>
 </attachment>
</attachments>
<creationDate>2015-01-29 14:46</creationDate>
<description>This is my first todo</description>
<forms>
 <form>
  <fields>
   <entry>
    <key>Straße_t</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
   </entry>
   <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>
   <entry>
    <key>Telefon_t</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
   </entry>
   <entry>
    <key>Ort_t</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
   </entry>
   <entry>
    <key>PLZ_t</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
   </entry>
  </fields>
  <id>41</id>
  <name>Kunde mobil</name>
 </form>
 <form>
  <fields>
   <entry>
    <key>t10</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">654645654325329</value>
   </entry>
   <entry>
    <key>t12</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
   </entry>
   <entry>
    <key>t13</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
   </entry>
   <entry>
    <key>4HKFT_t</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
   </entry>
   <entry>
    <key>5HKBez_t</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
   </entry>
   <entry>
    <key>K_ 5HKL_t</key>
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"></value>
   </entry>
  </fields>
  <id>42</id>
  <name>Projekterfassung Öl-Brennwert</name>
 </form>
</forms>
<id>14515</id>
<minutes>-843</minutes>
<ownerId>7</ownerId>
<priority>0</priority>
<properties/>
<scheduledEndDate>2015-01-29 23:54</scheduledEndDate>
<status>0</status>
<title> Yeah!</title>
</task>

This loads a representation of the ticket that you can edit and submit as an update of the existing ticket to the server - shown in the next chapter.

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, ie  http://yourtodoserver/ToDoServer/rest/tasks/14515. Please note that you have to use the corresponding content-type as in the following examples:

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 @- "http://yourtodoserver/ToDoServer/rest/tasks/14519"

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

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

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 can only edit tickets that are not yet finished.
  • 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.

Deleting of tickets via REST-call

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 "http://yourtodoserver/ToDoServer/rest/tasks/14517"

Searching tickets - archive search via REST

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.

If ie 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: task.id>14000 and task.title like '%Meier%'

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

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

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.