Project

General

Profile

Rest api » History » Version 51

Jean-Philippe Lang, 2011-11-20 15:33

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