Project

General

Profile

Rest api » History » Version 44

Jean-Philippe Lang, 2011-07-06 18:58
Added queries

1 26 Jean-Philippe Lang
{{>toc}}
2
3 1 Jean-Philippe Lang
h1. Redmine API
4
5
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
7
h2. API Description
8
9 24 Jean-Philippe Lang
|_.Resource                     |_.Status     |_.Notes  |_.Availability|
10
|[[Rest_Issues|Issues]]         | Beta        | Usable with some bugs and rough edges.  | 1.0 |
11
|[[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 39 Jean-Philippe Lang
|[[Rest_TimeEntries|Time Entries]]           | Beta | | 1.1 |
14 28 Jean-Philippe Lang
|[[Rest_News|News]]             | Prototype | Prototype implementation for @index@ only | 1.1 |
15 43 Jean-Philippe Lang
|[[Rest_IssueRelations|Issue Relations]]  | Alpha | | 1.3 |
16
|[[Rest_Versions|Versions]]  | Alpha | | 1.3 |
17 44 Jean-Philippe Lang
|[[Rest_Queries|Queries]]  | Alpha | | 1.3 |
18 24 Jean-Philippe Lang
19 15 Eric Davis
Status legend:
20 1 Jean-Philippe Lang
21
* Stable - feature complete, no major changes planned
22
* Beta - usable for integrations with some bugs or missing minor functionality
23
* Alpha - major functionality in place, needs feedback from API users and integrators
24
* Prototype - very rough implementation, possible major breaking changes mid-version. *Not recommended for integration*
25
* Planned - planned in a future version, depending on developer availability
26
27 24 Jean-Philippe Lang
h2. General topics
28 1 Jean-Philippe Lang
29 24 Jean-Philippe Lang
h3. Authentication
30
31
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:
32
* using your regular login/password via HTTP Basic authentication.
33 38 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 in one of the following way:
34
** passed in as a "key" parameter
35
** passed in as a username with a random password via HTTP Basic authentication
36
** passed in as a "Redmine-API-Key" HTTP header (added in Redmine 1.1.0)
37
38
You can find your API key on your account page ( /my/account ) when logged in, on the right-hand pane of the default layout.
39 24 Jean-Philippe Lang
40
h3. Collection resources and pagination
41
42
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:
43
44
* @offset@: the offset of the first object to retrieve
45
* @limit@: the number of items to be present in the response (default is 25, maximum is 100)
46
47 25 Jean-Philippe Lang
Alternatively, you can use the @page@ parameter, instead of @offset@, in conjunction with @limit@.
48 24 Jean-Philippe Lang
49
Examples:
50
51
<pre>
52
GET /issues.xml
53
=> returns the 25 first issues
54
55
GET /issues.xml?limit=100
56
=> returns the 100 first issues
57
58
GET /issues.xml?offset=30&limit=10
59
=> returns 10 issues from the 30th
60
61
GET /issues.xml?page=3&limit=10
62
=> same as above
63
</pre>
64
65
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:
66
67
<pre>
68
GET /issues.xml
69
70
<issues type="array" total_count="2595" limit="25" offset="0">
71
  ...
72
</issues>
73
</pre>
74
75
<pre>
76
GET /issues.json
77
78
{ "issues":[...], "total_count":2595, "limit":25, "offset":0 }
79
</pre>
80
81
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:
82
83
<pre>
84
GET /issues.xml?nometa=1
85
86
<issues type="array">
87
  ...
88
</issues>
89
</pre>
90 23 Jean-Philippe Lang
91 29 Etienne Massip
h3. Fetching associated data
92
93
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 :
94
95
Example:
96
97 41 Jean-Philippe Lang
To retrieve issue journals with its description:
98 29 Etienne Massip
99
<pre>
100
GET /issues/296.xml?include=journals
101
102
<issue>
103
  <id>296</id>
104 30 Etienne Massip
  ...
105 29 Etienne Massip
  <journals type="array">
106
  ...
107 1 Jean-Philippe Lang
  </journals>
108 41 Jean-Philippe Lang
</issue>
109
</pre>
110
111
You can also load multiple associations using a coma separated list of items.
112
113
Example:
114
115
<pre>
116
GET /issues/296.xml?include=journals,changesets
117
118
<issue>
119
  <id>296</id>
120
  ...
121
  <journals type="array">
122
  ...
123
  </journals>
124
  <changesets type="array">
125
  ...
126
  </changesets>
127 29 Etienne Massip
</issue>
128
</pre>
129
130 42 Jean-Philippe Lang
h3. Working with custom fields
131
132
Most of the Redmine objects support custom fields. Their values can be found in the @custom_fields@ attributes.
133
134
XML Example:
135
136
<pre>
137
GET /issues/296.xml      # an issue with 2 custom fields
138
139
<issue>
140
  <id>296</id>
141
  ...
142
  <custom_fields type="array">
143
    <custom_field name="Affected version" id="1">
144
      <value>1.0.1</value>
145
    </custom_field>
146
    <custom_field name="Resolution" id="2">
147
      <value>Fixed</value>
148
    </custom_field>
149
  </custom_fields>
150
</issue>
151
</pre>
152
153
JSON Example:
154
155
<pre>
156
GET /issues/296.json      # an issue with 2 custom fields
157
158
{"issue":
159
  {
160
    "id":8471,
161
    ...
162
    "custom_fields":
163
      [
164
        {"value":"1.0.1","name":"Affected version","id":1},
165
        {"value":"Fixed","name":"Resolution","id":2}
166
      ]
167
  }
168
}
169
</pre>
170
171
You can also set/change the values of the custom fields when creating/updating an object using the same syntax (except that the custom field name is not required).
172
173
XML Example:
174
175
<pre>
176
PUT /issues/296.xml
177
178
<issue>
179
  <subject>Updating custom fields of an issue</subject>
180
  ...
181
  <custom_fields type="array">
182
    <custom_field id="1">
183
      <value>1.0.2</value>
184
    </custom_field>
185
    <custom_field id="2">
186
      <value>Invalid</value>
187
    </custom_field>
188
  </custom_fields>
189
</issue>
190
</pre>
191
192
Note: the @type="array"@ attribute on @custom_fields@ XML tag is strictly required.
193
194
JSON Example:
195
196
<pre>
197
PUT /issues/296.json
198
199
{"issue":
200
  {
201
    "subject":"Updating custom fields of an issue",
202
    ...
203
    "custom_fields":
204
      [
205
        {"value":"1.0.2","id":1},
206
        {"value":"Invalid","id":2}
207
      ]
208
  }
209
}
210
</pre>
211
212 1 Jean-Philippe Lang
h2. API Usage in various languages/tools
213 5 Jean-Philippe Lang
214 1 Jean-Philippe Lang
* [[Rest_api_with_ruby|Ruby]]
215
* [[Rest_api_with_php|PHP]]
216 23 Jean-Philippe Lang
* [[Rest_api_with_python|Python]]
217 27 Jean-Philippe Lang
* [[Rest_api_with_java|Java]]
218 1 Jean-Philippe Lang
* [[Rest_api_with_curl|cURL]]
219 37 Bevan Rudge
* "Drupal Redmine API module, 2.x branch (currently not stable)":http://drupal.org/project/redmine