Rest api » History » Version 58
Jean-Philippe Lang, 2012-02-06 16:20
Typo.
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 | 56 | Jean-Philippe Lang | |[[Rest_Issues|Issues]] | Stable | Usable with some bugs and rough edges. | 1.0 | |
11 | |[[Rest_Projects|Projects]] | Stable | Usable with some bugs and rough edges. | 1.0 | |
||
12 | 55 | Jean-Philippe Lang | |[[Rest_Memberships|Project Memberships]] | Alpha | | 1.4 | |
13 | 56 | Jean-Philippe Lang | |[[Rest_Users|Users]] | Stable | | 1.1 | |
14 | |[[Rest_TimeEntries|Time Entries]] | Stable | | 1.1 | |
||
15 | 28 | Jean-Philippe Lang | |[[Rest_News|News]] | Prototype | Prototype implementation for @index@ only | 1.1 | |
16 | 43 | Jean-Philippe Lang | |[[Rest_IssueRelations|Issue Relations]] | Alpha | | 1.3 | |
17 | |[[Rest_Versions|Versions]] | Alpha | | 1.3 | |
||
18 | 44 | Jean-Philippe Lang | |[[Rest_Queries|Queries]] | Alpha | | 1.3 | |
19 | 45 | Jean-Philippe Lang | |[[Rest_Attachments|Attachments]] | Alpha | | 1.3 | |
20 | 53 | Jean-Philippe Lang | |[[Rest_IssueStatuses|Issue Statuses]] | Alpha | Provides the list of all statuses | 1.3 | |
21 | 51 | Jean-Philippe Lang | |[[Rest_Trackers|Trackers]] | Alpha | Provides the list of all trackers | 1.3 | |
22 | 52 | Jean-Philippe Lang | |[[Rest_IssueCategories|Issue Categories]] | Alpha | | 1.3 | |
23 | 55 | Jean-Philippe Lang | |[[Rest_Roles|Roles]] | Alpha | | 1.4 | |
24 | 24 | Jean-Philippe Lang | |
25 | 15 | Eric Davis | Status legend: |
26 | 1 | Jean-Philippe Lang | |
27 | * Stable - feature complete, no major changes planned |
||
28 | * Beta - usable for integrations with some bugs or missing minor functionality |
||
29 | * Alpha - major functionality in place, needs feedback from API users and integrators |
||
30 | * Prototype - very rough implementation, possible major breaking changes mid-version. *Not recommended for integration* |
||
31 | * Planned - planned in a future version, depending on developer availability |
||
32 | |||
33 | 24 | Jean-Philippe Lang | h2. General topics |
34 | 1 | Jean-Philippe Lang | |
35 | 24 | Jean-Philippe Lang | h3. Authentication |
36 | |||
37 | 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: |
||
38 | * using your regular login/password via HTTP Basic authentication. |
||
39 | 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: |
40 | ** passed in as a "key" parameter |
||
41 | ** passed in as a username with a random password via HTTP Basic authentication |
||
42 | 46 | John Galambos | ** passed in as a "X-Redmine-API-Key" HTTP header (added in Redmine 1.1.0) |
43 | 38 | Jean-Philippe Lang | |
44 | You can find your API key on your account page ( /my/account ) when logged in, on the right-hand pane of the default layout. |
||
45 | 24 | Jean-Philippe Lang | |
46 | h3. Collection resources and pagination |
||
47 | |||
48 | 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: |
49 | 24 | Jean-Philippe Lang | |
50 | * @offset@: the offset of the first object to retrieve |
||
51 | * @limit@: the number of items to be present in the response (default is 25, maximum is 100) |
||
52 | |||
53 | 25 | Jean-Philippe Lang | Alternatively, you can use the @page@ parameter, instead of @offset@, in conjunction with @limit@. |
54 | 24 | Jean-Philippe Lang | |
55 | Examples: |
||
56 | |||
57 | <pre> |
||
58 | GET /issues.xml |
||
59 | => returns the 25 first issues |
||
60 | |||
61 | GET /issues.xml?limit=100 |
||
62 | => returns the 100 first issues |
||
63 | |||
64 | GET /issues.xml?offset=30&limit=10 |
||
65 | => returns 10 issues from the 30th |
||
66 | |||
67 | GET /issues.xml?page=3&limit=10 |
||
68 | => same as above |
||
69 | </pre> |
||
70 | |||
71 | 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: |
||
72 | |||
73 | <pre> |
||
74 | GET /issues.xml |
||
75 | |||
76 | <issues type="array" total_count="2595" limit="25" offset="0"> |
||
77 | ... |
||
78 | </issues> |
||
79 | </pre> |
||
80 | |||
81 | <pre> |
||
82 | GET /issues.json |
||
83 | |||
84 | { "issues":[...], "total_count":2595, "limit":25, "offset":0 } |
||
85 | </pre> |
||
86 | |||
87 | 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: |
||
88 | |||
89 | <pre> |
||
90 | GET /issues.xml?nometa=1 |
||
91 | |||
92 | <issues type="array"> |
||
93 | ... |
||
94 | </issues> |
||
95 | </pre> |
||
96 | 23 | Jean-Philippe Lang | |
97 | 29 | Etienne Massip | h3. Fetching associated data |
98 | |||
99 | 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 : |
||
100 | |||
101 | Example: |
||
102 | |||
103 | 41 | Jean-Philippe Lang | To retrieve issue journals with its description: |
104 | 29 | Etienne Massip | |
105 | <pre> |
||
106 | GET /issues/296.xml?include=journals |
||
107 | |||
108 | <issue> |
||
109 | <id>296</id> |
||
110 | 30 | Etienne Massip | ... |
111 | 29 | Etienne Massip | <journals type="array"> |
112 | ... |
||
113 | 1 | Jean-Philippe Lang | </journals> |
114 | 41 | Jean-Philippe Lang | </issue> |
115 | </pre> |
||
116 | |||
117 | You can also load multiple associations using a coma separated list of items. |
||
118 | |||
119 | Example: |
||
120 | |||
121 | <pre> |
||
122 | GET /issues/296.xml?include=journals,changesets |
||
123 | |||
124 | <issue> |
||
125 | <id>296</id> |
||
126 | ... |
||
127 | <journals type="array"> |
||
128 | ... |
||
129 | </journals> |
||
130 | <changesets type="array"> |
||
131 | ... |
||
132 | </changesets> |
||
133 | 29 | Etienne Massip | </issue> |
134 | </pre> |
||
135 | |||
136 | 42 | Jean-Philippe Lang | h3. Working with custom fields |
137 | |||
138 | Most of the Redmine objects support custom fields. Their values can be found in the @custom_fields@ attributes. |
||
139 | |||
140 | XML Example: |
||
141 | |||
142 | <pre> |
||
143 | GET /issues/296.xml # an issue with 2 custom fields |
||
144 | |||
145 | <issue> |
||
146 | <id>296</id> |
||
147 | ... |
||
148 | <custom_fields type="array"> |
||
149 | <custom_field name="Affected version" id="1"> |
||
150 | <value>1.0.1</value> |
||
151 | </custom_field> |
||
152 | <custom_field name="Resolution" id="2"> |
||
153 | <value>Fixed</value> |
||
154 | </custom_field> |
||
155 | </custom_fields> |
||
156 | </issue> |
||
157 | </pre> |
||
158 | |||
159 | JSON Example: |
||
160 | |||
161 | <pre> |
||
162 | GET /issues/296.json # an issue with 2 custom fields |
||
163 | |||
164 | {"issue": |
||
165 | { |
||
166 | "id":8471, |
||
167 | ... |
||
168 | "custom_fields": |
||
169 | [ |
||
170 | {"value":"1.0.1","name":"Affected version","id":1}, |
||
171 | {"value":"Fixed","name":"Resolution","id":2} |
||
172 | ] |
||
173 | } |
||
174 | } |
||
175 | </pre> |
||
176 | |||
177 | 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). |
||
178 | |||
179 | XML Example: |
||
180 | |||
181 | <pre> |
||
182 | PUT /issues/296.xml |
||
183 | |||
184 | <issue> |
||
185 | <subject>Updating custom fields of an issue</subject> |
||
186 | ... |
||
187 | <custom_fields type="array"> |
||
188 | <custom_field id="1"> |
||
189 | <value>1.0.2</value> |
||
190 | </custom_field> |
||
191 | <custom_field id="2"> |
||
192 | <value>Invalid</value> |
||
193 | </custom_field> |
||
194 | </custom_fields> |
||
195 | </issue> |
||
196 | </pre> |
||
197 | |||
198 | Note: the @type="array"@ attribute on @custom_fields@ XML tag is strictly required. |
||
199 | |||
200 | JSON Example: |
||
201 | |||
202 | <pre> |
||
203 | PUT /issues/296.json |
||
204 | |||
205 | {"issue": |
||
206 | { |
||
207 | "subject":"Updating custom fields of an issue", |
||
208 | ... |
||
209 | "custom_fields": |
||
210 | [ |
||
211 | {"value":"1.0.2","id":1}, |
||
212 | {"value":"Invalid","id":2} |
||
213 | ] |
||
214 | } |
||
215 | } |
||
216 | </pre> |
||
217 | |||
218 | 1 | Jean-Philippe Lang | h2. API Usage in various languages/tools |
219 | 5 | Jean-Philippe Lang | |
220 | 1 | Jean-Philippe Lang | * [[Rest_api_with_ruby|Ruby]] |
221 | * [[Rest_api_with_php|PHP]] |
||
222 | 23 | Jean-Philippe Lang | * [[Rest_api_with_python|Python]] |
223 | 27 | Jean-Philippe Lang | * [[Rest_api_with_java|Java]] |
224 | 1 | Jean-Philippe Lang | * [[Rest_api_with_curl|cURL]] |
225 | 37 | Bevan Rudge | * "Drupal Redmine API module, 2.x branch (currently not stable)":http://drupal.org/project/redmine |
226 | 48 | Dorin Huzum | * [[Rest_api_with_csharp|.NET]] |
227 | 49 | Rodrigo Carvalho | * [[Rest_api_with_delphi|Delphi]] |
228 | 54 | Jean-Philippe Lang | |
229 | h2. API Change history |
||
230 | |||
231 | 58 | Jean-Philippe Lang | This section lists changes to the existing API features only. New features of the API are listed in the [[Rest_api#API-Description|API Description]]. |
232 | 57 | Jean-Philippe Lang | |
233 | 54 | Jean-Philippe Lang | h3. 2012-01-29: Multiselect custom fields (r8721, version:1.4.0) |
234 | |||
235 | Custom fields with multiple values are now supported in Redmine and may be found in API responses. These custom fields have a @multiple=true attribute@ and their @value@ attribute is an array. |
||
236 | |||
237 | Example: |
||
238 | |||
239 | <pre> |
||
240 | GET /issues/296.json |
||
241 | |||
242 | {"issue": |
||
243 | { |
||
244 | "id":8471, |
||
245 | ... |
||
246 | "custom_fields": |
||
247 | [ |
||
248 | {"value":["1.0.1","1.0.2"],"multiple":true,"name":"Affected version","id":1}, |
||
249 | {"value":"Fixed","name":"Resolution","id":2} |
||
250 | ] |
||
251 | } |
||
252 | } |
||
253 | </pre> |