Rest api » History » Version 29

Etienne Massip, 2011-02-16 10:41

1 26 Jean-Philippe Lang
{{>toc}}
2 26 Jean-Philippe Lang
3 1 Jean-Philippe Lang
h1. Redmine API
4 1 Jean-Philippe Lang
5 1 Jean-Philippe Lang
Redmine exposes some of its data through a REST API. This API provides access and basic CRUD operations (create, update, delete) for the resources described below.
6 1 Jean-Philippe Lang
7 1 Jean-Philippe Lang
h2. API Description
8 1 Jean-Philippe Lang
9 24 Jean-Philippe Lang
|_.Resource                     |_.Status     |_.Notes  |_.Availability|
10 24 Jean-Philippe Lang
|[[Rest_Issues|Issues]]         | Beta        | Usable with some bugs and rough edges.  | 1.0 |
11 24 Jean-Philippe Lang
|[[Rest_Projects|Projects]]     | Beta        | Usable with some bugs and rough edges.  | 1.0 |
12 28 Jean-Philippe Lang
|[[Rest_Users|Users]]           | Beta | | 1.1 |
13 28 Jean-Philippe Lang
|[[Rest_TimeEntries|TimeEntries]]           | Beta | | 1.1 |
14 28 Jean-Philippe Lang
|[[Rest_News|News]]             | Prototype | Prototype implementation for @index@ only | 1.1 |
15 24 Jean-Philippe Lang
|[[Rest_WikiPages|Wiki Pages]]  | Planned | | 1.2 |
16 24 Jean-Philippe Lang
17 15 Eric Davis
Status legend:
18 1 Jean-Philippe Lang
19 1 Jean-Philippe Lang
* Stable - feature complete, no major changes planned
20 1 Jean-Philippe Lang
* Beta - usable for integrations with some bugs or missing minor functionality
21 1 Jean-Philippe Lang
* Alpha - major functionality in place, needs feedback from API users and integrators
22 1 Jean-Philippe Lang
* Prototype - very rough implementation, possible major breaking changes mid-version. *Not recommended for integration*
23 1 Jean-Philippe Lang
* Planned - planned in a future version, depending on developer availability
24 1 Jean-Philippe Lang
25 24 Jean-Philippe Lang
h2. General topics
26 1 Jean-Philippe Lang
27 24 Jean-Philippe Lang
h3. Authentication
28 24 Jean-Philippe Lang
29 24 Jean-Philippe Lang
Most of the time, the API requires authentication. To enable the API-style authentication, you have to check *Enable REST API* in Administration -> Settings -> Authentication. Then, authentication can be done in 2 different ways:
30 24 Jean-Philippe Lang
* using your regular login/password via HTTP Basic authentication.
31 24 Jean-Philippe Lang
* using your API key which is a handy way to avoid putting a password in a script. The API key may be attached to each request as a "key" parameter or it may be passed in as a username with a random password. You can find your API key on your account page ( /my/account ) when logged in, on the right-hand pane of the default layout.
32 24 Jean-Philippe Lang
33 24 Jean-Philippe Lang
h3. Collection resources and pagination
34 24 Jean-Philippe Lang
35 24 Jean-Philippe Lang
The response to a GET request on a collection ressources (eg. @/issues.xml@, @/users.xml@) generally won't return all the objets available in your database. Redmine version:1.1.0 introduces a common way to query such ressources using the following parameters:
36 24 Jean-Philippe Lang
37 24 Jean-Philippe Lang
* @offset@: the offset of the first object to retrieve
38 24 Jean-Philippe Lang
* @limit@: the number of items to be present in the response (default is 25, maximum is 100)
39 24 Jean-Philippe Lang
40 25 Jean-Philippe Lang
Alternatively, you can use the @page@ parameter, instead of @offset@, in conjunction with @limit@.
41 24 Jean-Philippe Lang
42 24 Jean-Philippe Lang
Examples:
43 24 Jean-Philippe Lang
44 24 Jean-Philippe Lang
<pre>
45 24 Jean-Philippe Lang
GET /issues.xml
46 24 Jean-Philippe Lang
=> returns the 25 first issues
47 24 Jean-Philippe Lang
48 24 Jean-Philippe Lang
GET /issues.xml?limit=100
49 24 Jean-Philippe Lang
=> returns the 100 first issues
50 24 Jean-Philippe Lang
51 24 Jean-Philippe Lang
GET /issues.xml?offset=30&limit=10
52 24 Jean-Philippe Lang
=> returns 10 issues from the 30th
53 24 Jean-Philippe Lang
54 24 Jean-Philippe Lang
GET /issues.xml?page=3&limit=10
55 24 Jean-Philippe Lang
=> same as above
56 24 Jean-Philippe Lang
</pre>
57 24 Jean-Philippe Lang
58 24 Jean-Philippe Lang
Responses to GET requests on collection ressources provide information about the total object count available in Redmine and the offset/limit used for the response. Examples:
59 24 Jean-Philippe Lang
60 24 Jean-Philippe Lang
<pre>
61 24 Jean-Philippe Lang
GET /issues.xml
62 24 Jean-Philippe Lang
63 24 Jean-Philippe Lang
<issues type="array" total_count="2595" limit="25" offset="0">
64 24 Jean-Philippe Lang
  ...
65 24 Jean-Philippe Lang
</issues>
66 24 Jean-Philippe Lang
</pre>
67 24 Jean-Philippe Lang
68 24 Jean-Philippe Lang
<pre>
69 24 Jean-Philippe Lang
GET /issues.json
70 24 Jean-Philippe Lang
71 24 Jean-Philippe Lang
{ "issues":[...], "total_count":2595, "limit":25, "offset":0 }
72 24 Jean-Philippe Lang
</pre>
73 24 Jean-Philippe Lang
74 24 Jean-Philippe Lang
Note: if you're using a REST client that does not support such top level attributes (total_count, limit, offset), you can set the @nometa@ parameter or @X-Redmine-Nometa@ HTTP header to 1 to get responses without them. Example:
75 24 Jean-Philippe Lang
76 24 Jean-Philippe Lang
<pre>
77 24 Jean-Philippe Lang
GET /issues.xml?nometa=1
78 24 Jean-Philippe Lang
79 24 Jean-Philippe Lang
<issues type="array">
80 24 Jean-Philippe Lang
  ...
81 24 Jean-Philippe Lang
</issues>
82 24 Jean-Philippe Lang
</pre>
83 23 Jean-Philippe Lang
84 29 Etienne Massip
h3. Fetching associated data
85 29 Etienne Massip
86 29 Etienne Massip
Since of version:1.1.0, you have to explicitly specify the associations you want to be included in the query result by appending the @include@ parameter to the query url :
87 29 Etienne Massip
88 29 Etienne Massip
Example:
89 29 Etienne Massip
90 29 Etienne Massip
To retrieve issue journals with its description :
91 29 Etienne Massip
92 29 Etienne Massip
<pre>
93 29 Etienne Massip
GET /issues/296.xml?include=journals
94 29 Etienne Massip
95 29 Etienne Massip
<issue>
96 29 Etienne Massip
  <id>296</id>
97 29 Etienne Massip
  <journals type="array">
98 29 Etienne Massip
  ...
99 29 Etienne Massip
  </journals>
100 29 Etienne Massip
</issue>
101 29 Etienne Massip
</pre>
102 29 Etienne Massip
103 1 Jean-Philippe Lang
h2. API Usage in various languages/tools
104 5 Jean-Philippe Lang
105 1 Jean-Philippe Lang
* [[Rest_api_with_ruby|Ruby]]
106 1 Jean-Philippe Lang
* [[Rest_api_with_php|PHP]]
107 23 Jean-Philippe Lang
* [[Rest_api_with_python|Python]]
108 27 Jean-Philippe Lang
* [[Rest_api_with_java|Java]]
109 1 Jean-Philippe Lang
* [[Rest_api_with_curl|cURL]]