Rest api
Version 60 (Jean-Philippe Lang, 2012-02-06 17:09)
| 1 | 32 | Felix Schäfer | {{>toc}} |
|---|---|---|---|
| 2 | 32 | Felix Schäfer | |
| 3 | 1 | Jean-Philippe Lang | h1. Redmine API |
| 4 | 1 | Jean-Philippe Lang | |
| 5 | 60 | 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. The API supports both "XML":http://en.wikipedia.org/wiki/Xml and "JSON":http://en.wikipedia.org/wiki/JSON formats. |
| 6 | 1 | Jean-Philippe Lang | |
| 7 | 32 | Felix Schäfer | h2. API Description |
| 8 | 1 | Jean-Philippe Lang | |
| 9 | 32 | Felix Schäfer | |_.Resource |_.Status |_.Notes |_.Availability| |
| 10 | 56 | Jean-Philippe Lang | |[[Rest_Issues|Issues]] | Stable | Usable with some bugs and rough edges. | 1.0 | |
| 11 | 56 | Jean-Philippe Lang | |[[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 | 56 | Jean-Philippe Lang | |[[Rest_TimeEntries|Time Entries]] | Stable | | 1.1 | |
| 15 | 32 | Felix Schäfer | |[[Rest_News|News]] | Prototype | Prototype implementation for @index@ only | 1.1 | |
| 16 | 43 | Jean-Philippe Lang | |[[Rest_IssueRelations|Issue Relations]] | Alpha | | 1.3 | |
| 17 | 43 | Jean-Philippe Lang | |[[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 | 1 | Jean-Philippe Lang | |
| 25 | 32 | Felix Schäfer | Status legend: |
| 26 | 1 | Jean-Philippe Lang | |
| 27 | 32 | Felix Schäfer | * Stable - feature complete, no major changes planned |
| 28 | 32 | Felix Schäfer | * Beta - usable for integrations with some bugs or missing minor functionality |
| 29 | 32 | Felix Schäfer | * Alpha - major functionality in place, needs feedback from API users and integrators |
| 30 | 32 | Felix Schäfer | * Prototype - very rough implementation, possible major breaking changes mid-version. *Not recommended for integration* |
| 31 | 32 | Felix Schäfer | * Planned - planned in a future version, depending on developer availability |
| 32 | 1 | Jean-Philippe Lang | |
| 33 | 32 | Felix Schäfer | h2. General topics |
| 34 | 1 | Jean-Philippe Lang | |
| 35 | 32 | Felix Schäfer | h3. Authentication |
| 36 | 1 | Jean-Philippe Lang | |
| 37 | 32 | Felix Schäfer | 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 | 32 | Felix Schäfer | * 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 | 38 | Jean-Philippe Lang | ** passed in as a "key" parameter |
| 41 | 38 | Jean-Philippe Lang | ** 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 | 38 | Jean-Philippe Lang | 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 | 32 | Felix Schäfer | |
| 46 | 32 | Felix Schäfer | h3. Collection resources and pagination |
| 47 | 32 | Felix Schäfer | |
| 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 | 32 | Felix Schäfer | |
| 50 | 32 | Felix Schäfer | * @offset@: the offset of the first object to retrieve |
| 51 | 32 | Felix Schäfer | * @limit@: the number of items to be present in the response (default is 25, maximum is 100) |
| 52 | 32 | Felix Schäfer | |
| 53 | 32 | Felix Schäfer | Alternatively, you can use the @page@ parameter, instead of @offset@, in conjunction with @limit@. |
| 54 | 32 | Felix Schäfer | |
| 55 | 32 | Felix Schäfer | Examples: |
| 56 | 32 | Felix Schäfer | |
| 57 | 32 | Felix Schäfer | <pre> |
| 58 | 32 | Felix Schäfer | GET /issues.xml |
| 59 | 32 | Felix Schäfer | => returns the 25 first issues |
| 60 | 32 | Felix Schäfer | |
| 61 | 32 | Felix Schäfer | GET /issues.xml?limit=100 |
| 62 | 32 | Felix Schäfer | => returns the 100 first issues |
| 63 | 32 | Felix Schäfer | |
| 64 | 32 | Felix Schäfer | GET /issues.xml?offset=30&limit=10 |
| 65 | 32 | Felix Schäfer | => returns 10 issues from the 30th |
| 66 | 32 | Felix Schäfer | |
| 67 | 32 | Felix Schäfer | GET /issues.xml?page=3&limit=10 |
| 68 | 32 | Felix Schäfer | => same as above |
| 69 | 32 | Felix Schäfer | </pre> |
| 70 | 32 | Felix Schäfer | |
| 71 | 32 | Felix Schäfer | 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 | 32 | Felix Schäfer | |
| 73 | 32 | Felix Schäfer | <pre> |
| 74 | 32 | Felix Schäfer | GET /issues.xml |
| 75 | 32 | Felix Schäfer | |
| 76 | 32 | Felix Schäfer | <issues type="array" total_count="2595" limit="25" offset="0"> |
| 77 | 32 | Felix Schäfer | ... |
| 78 | 32 | Felix Schäfer | </issues> |
| 79 | 32 | Felix Schäfer | </pre> |
| 80 | 32 | Felix Schäfer | |
| 81 | 32 | Felix Schäfer | <pre> |
| 82 | 32 | Felix Schäfer | GET /issues.json |
| 83 | 32 | Felix Schäfer | |
| 84 | 32 | Felix Schäfer | { "issues":[...], "total_count":2595, "limit":25, "offset":0 } |
| 85 | 32 | Felix Schäfer | </pre> |
| 86 | 32 | Felix Schäfer | |
| 87 | 32 | Felix Schäfer | 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 | 32 | Felix Schäfer | |
| 89 | 32 | Felix Schäfer | <pre> |
| 90 | 32 | Felix Schäfer | GET /issues.xml?nometa=1 |
| 91 | 32 | Felix Schäfer | |
| 92 | 32 | Felix Schäfer | <issues type="array"> |
| 93 | 32 | Felix Schäfer | ... |
| 94 | 32 | Felix Schäfer | </issues> |
| 95 | 32 | Felix Schäfer | </pre> |
| 96 | 32 | Felix Schäfer | |
| 97 | 32 | Felix Schäfer | h3. Fetching associated data |
| 98 | 32 | Felix Schäfer | |
| 99 | 32 | Felix Schäfer | 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 | 32 | Felix Schäfer | |
| 101 | 32 | Felix Schäfer | Example: |
| 102 | 32 | Felix Schäfer | |
| 103 | 41 | Jean-Philippe Lang | To retrieve issue journals with its description: |
| 104 | 32 | Felix Schäfer | |
| 105 | 32 | Felix Schäfer | <pre> |
| 106 | 32 | Felix Schäfer | GET /issues/296.xml?include=journals |
| 107 | 32 | Felix Schäfer | |
| 108 | 32 | Felix Schäfer | <issue> |
| 109 | 32 | Felix Schäfer | <id>296</id> |
| 110 | 32 | Felix Schäfer | ... |
| 111 | 32 | Felix Schäfer | <journals type="array"> |
| 112 | 32 | Felix Schäfer | ... |
| 113 | 1 | Jean-Philippe Lang | </journals> |
| 114 | 41 | Jean-Philippe Lang | </issue> |
| 115 | 41 | Jean-Philippe Lang | </pre> |
| 116 | 41 | Jean-Philippe Lang | |
| 117 | 41 | Jean-Philippe Lang | You can also load multiple associations using a coma separated list of items. |
| 118 | 41 | Jean-Philippe Lang | |
| 119 | 41 | Jean-Philippe Lang | Example: |
| 120 | 41 | Jean-Philippe Lang | |
| 121 | 41 | Jean-Philippe Lang | <pre> |
| 122 | 41 | Jean-Philippe Lang | GET /issues/296.xml?include=journals,changesets |
| 123 | 41 | Jean-Philippe Lang | |
| 124 | 41 | Jean-Philippe Lang | <issue> |
| 125 | 41 | Jean-Philippe Lang | <id>296</id> |
| 126 | 41 | Jean-Philippe Lang | ... |
| 127 | 41 | Jean-Philippe Lang | <journals type="array"> |
| 128 | 41 | Jean-Philippe Lang | ... |
| 129 | 41 | Jean-Philippe Lang | </journals> |
| 130 | 41 | Jean-Philippe Lang | <changesets type="array"> |
| 131 | 41 | Jean-Philippe Lang | ... |
| 132 | 41 | Jean-Philippe Lang | </changesets> |
| 133 | 32 | Felix Schäfer | </issue> |
| 134 | 32 | Felix Schäfer | </pre> |
| 135 | 32 | Felix Schäfer | |
| 136 | 42 | Jean-Philippe Lang | h3. Working with custom fields |
| 137 | 42 | Jean-Philippe Lang | |
| 138 | 42 | Jean-Philippe Lang | Most of the Redmine objects support custom fields. Their values can be found in the @custom_fields@ attributes. |
| 139 | 42 | Jean-Philippe Lang | |
| 140 | 42 | Jean-Philippe Lang | XML Example: |
| 141 | 42 | Jean-Philippe Lang | |
| 142 | 42 | Jean-Philippe Lang | <pre> |
| 143 | 42 | Jean-Philippe Lang | GET /issues/296.xml # an issue with 2 custom fields |
| 144 | 42 | Jean-Philippe Lang | |
| 145 | 42 | Jean-Philippe Lang | <issue> |
| 146 | 42 | Jean-Philippe Lang | <id>296</id> |
| 147 | 42 | Jean-Philippe Lang | ... |
| 148 | 42 | Jean-Philippe Lang | <custom_fields type="array"> |
| 149 | 42 | Jean-Philippe Lang | <custom_field name="Affected version" id="1"> |
| 150 | 42 | Jean-Philippe Lang | <value>1.0.1</value> |
| 151 | 42 | Jean-Philippe Lang | </custom_field> |
| 152 | 42 | Jean-Philippe Lang | <custom_field name="Resolution" id="2"> |
| 153 | 42 | Jean-Philippe Lang | <value>Fixed</value> |
| 154 | 42 | Jean-Philippe Lang | </custom_field> |
| 155 | 42 | Jean-Philippe Lang | </custom_fields> |
| 156 | 42 | Jean-Philippe Lang | </issue> |
| 157 | 42 | Jean-Philippe Lang | </pre> |
| 158 | 42 | Jean-Philippe Lang | |
| 159 | 42 | Jean-Philippe Lang | JSON Example: |
| 160 | 42 | Jean-Philippe Lang | |
| 161 | 42 | Jean-Philippe Lang | <pre> |
| 162 | 42 | Jean-Philippe Lang | GET /issues/296.json # an issue with 2 custom fields |
| 163 | 42 | Jean-Philippe Lang | |
| 164 | 42 | Jean-Philippe Lang | {"issue": |
| 165 | 42 | Jean-Philippe Lang | { |
| 166 | 42 | Jean-Philippe Lang | "id":8471, |
| 167 | 42 | Jean-Philippe Lang | ... |
| 168 | 42 | Jean-Philippe Lang | "custom_fields": |
| 169 | 42 | Jean-Philippe Lang | [ |
| 170 | 42 | Jean-Philippe Lang | {"value":"1.0.1","name":"Affected version","id":1}, |
| 171 | 42 | Jean-Philippe Lang | {"value":"Fixed","name":"Resolution","id":2} |
| 172 | 42 | Jean-Philippe Lang | ] |
| 173 | 42 | Jean-Philippe Lang | } |
| 174 | 42 | Jean-Philippe Lang | } |
| 175 | 42 | Jean-Philippe Lang | </pre> |
| 176 | 42 | Jean-Philippe Lang | |
| 177 | 42 | Jean-Philippe Lang | 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 | 42 | Jean-Philippe Lang | |
| 179 | 42 | Jean-Philippe Lang | XML Example: |
| 180 | 42 | Jean-Philippe Lang | |
| 181 | 42 | Jean-Philippe Lang | <pre> |
| 182 | 42 | Jean-Philippe Lang | PUT /issues/296.xml |
| 183 | 42 | Jean-Philippe Lang | |
| 184 | 42 | Jean-Philippe Lang | <issue> |
| 185 | 42 | Jean-Philippe Lang | <subject>Updating custom fields of an issue</subject> |
| 186 | 42 | Jean-Philippe Lang | ... |
| 187 | 42 | Jean-Philippe Lang | <custom_fields type="array"> |
| 188 | 42 | Jean-Philippe Lang | <custom_field id="1"> |
| 189 | 42 | Jean-Philippe Lang | <value>1.0.2</value> |
| 190 | 42 | Jean-Philippe Lang | </custom_field> |
| 191 | 42 | Jean-Philippe Lang | <custom_field id="2"> |
| 192 | 42 | Jean-Philippe Lang | <value>Invalid</value> |
| 193 | 42 | Jean-Philippe Lang | </custom_field> |
| 194 | 42 | Jean-Philippe Lang | </custom_fields> |
| 195 | 42 | Jean-Philippe Lang | </issue> |
| 196 | 42 | Jean-Philippe Lang | </pre> |
| 197 | 42 | Jean-Philippe Lang | |
| 198 | 42 | Jean-Philippe Lang | Note: the @type="array"@ attribute on @custom_fields@ XML tag is strictly required. |
| 199 | 42 | Jean-Philippe Lang | |
| 200 | 42 | Jean-Philippe Lang | JSON Example: |
| 201 | 42 | Jean-Philippe Lang | |
| 202 | 42 | Jean-Philippe Lang | <pre> |
| 203 | 42 | Jean-Philippe Lang | PUT /issues/296.json |
| 204 | 42 | Jean-Philippe Lang | |
| 205 | 42 | Jean-Philippe Lang | {"issue": |
| 206 | 42 | Jean-Philippe Lang | { |
| 207 | 42 | Jean-Philippe Lang | "subject":"Updating custom fields of an issue", |
| 208 | 42 | Jean-Philippe Lang | ... |
| 209 | 42 | Jean-Philippe Lang | "custom_fields": |
| 210 | 42 | Jean-Philippe Lang | [ |
| 211 | 42 | Jean-Philippe Lang | {"value":"1.0.2","id":1}, |
| 212 | 42 | Jean-Philippe Lang | {"value":"Invalid","id":2} |
| 213 | 42 | Jean-Philippe Lang | ] |
| 214 | 42 | Jean-Philippe Lang | } |
| 215 | 42 | Jean-Philippe Lang | } |
| 216 | 42 | Jean-Philippe Lang | </pre> |
| 217 | 42 | Jean-Philippe Lang | |
| 218 | 59 | Jean-Philippe Lang | h3. Validation errors |
| 219 | 59 | Jean-Philippe Lang | |
| 220 | 59 | Jean-Philippe Lang | When trying to create or update an object with invalid or missing attribute parameters, you will get a @422 Unprocessable Entity@ response. That means that the object could not be created or updated. In such cases, the response body contains the corresponding error messages: |
| 221 | 59 | Jean-Philippe Lang | |
| 222 | 59 | Jean-Philippe Lang | +XML Example+: |
| 223 | 59 | Jean-Philippe Lang | |
| 224 | 59 | Jean-Philippe Lang | <pre> |
| 225 | 59 | Jean-Philippe Lang | # Request with invalid or missing attributes |
| 226 | 59 | Jean-Philippe Lang | POST /users.xml |
| 227 | 59 | Jean-Philippe Lang | <user> |
| 228 | 59 | Jean-Philippe Lang | <login>john</login> |
| 229 | 59 | Jean-Philippe Lang | <lastname>Smith</lastname> |
| 230 | 59 | Jean-Philippe Lang | <mail>john</mail> |
| 231 | 59 | Jean-Philippe Lang | </uer> |
| 232 | 59 | Jean-Philippe Lang | |
| 233 | 59 | Jean-Philippe Lang | # 422 response with the error messages in its body |
| 234 | 59 | Jean-Philippe Lang | <errors> |
| 235 | 59 | Jean-Philippe Lang | <error>First name can't be blank</error> |
| 236 | 59 | Jean-Philippe Lang | <error>Email is invalid</error> |
| 237 | 59 | Jean-Philippe Lang | </errors> |
| 238 | 59 | Jean-Philippe Lang | </pre> |
| 239 | 59 | Jean-Philippe Lang | |
| 240 | 59 | Jean-Philippe Lang | |
| 241 | 59 | Jean-Philippe Lang | +JSON Example+: |
| 242 | 59 | Jean-Philippe Lang | |
| 243 | 59 | Jean-Philippe Lang | <pre> |
| 244 | 59 | Jean-Philippe Lang | # Request with invalid or missing attributes |
| 245 | 59 | Jean-Philippe Lang | POST /users.json |
| 246 | 59 | Jean-Philippe Lang | { |
| 247 | 59 | Jean-Philippe Lang | "user":{ |
| 248 | 59 | Jean-Philippe Lang | "login":"john", |
| 249 | 59 | Jean-Philippe Lang | "lastname":"Smith", |
| 250 | 59 | Jean-Philippe Lang | "mail":"john" |
| 251 | 59 | Jean-Philippe Lang | } |
| 252 | 59 | Jean-Philippe Lang | } |
| 253 | 59 | Jean-Philippe Lang | |
| 254 | 59 | Jean-Philippe Lang | # 422 response with the error messages in its body |
| 255 | 59 | Jean-Philippe Lang | { |
| 256 | 59 | Jean-Philippe Lang | "errors":[ |
| 257 | 59 | Jean-Philippe Lang | "First name can't be blank", |
| 258 | 59 | Jean-Philippe Lang | "Email is invalid" |
| 259 | 59 | Jean-Philippe Lang | ] |
| 260 | 59 | Jean-Philippe Lang | } |
| 261 | 59 | Jean-Philippe Lang | </pre> |
| 262 | 59 | Jean-Philippe Lang | |
| 263 | 32 | Felix Schäfer | h2. API Usage in various languages/tools |
| 264 | 32 | Felix Schäfer | |
| 265 | 32 | Felix Schäfer | * [[Rest_api_with_ruby|Ruby]] |
| 266 | 32 | Felix Schäfer | * [[Rest_api_with_php|PHP]] |
| 267 | 32 | Felix Schäfer | * [[Rest_api_with_python|Python]] |
| 268 | 32 | Felix Schäfer | * [[Rest_api_with_java|Java]] |
| 269 | 32 | Felix Schäfer | * [[Rest_api_with_curl|cURL]] |
| 270 | 37 | Bevan Rudge | * "Drupal Redmine API module, 2.x branch (currently not stable)":http://drupal.org/project/redmine |
| 271 | 48 | Dorin Huzum | * [[Rest_api_with_csharp|.NET]] |
| 272 | 49 | Rodrigo Carvalho | * [[Rest_api_with_delphi|Delphi]] |
| 273 | 54 | Jean-Philippe Lang | |
| 274 | 54 | Jean-Philippe Lang | h2. API Change history |
| 275 | 54 | Jean-Philippe Lang | |
| 276 | 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]]. |
| 277 | 57 | Jean-Philippe Lang | |
| 278 | 54 | Jean-Philippe Lang | h3. 2012-01-29: Multiselect custom fields (r8721, version:1.4.0) |
| 279 | 54 | Jean-Philippe Lang | |
| 280 | 54 | Jean-Philippe Lang | 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. |
| 281 | 54 | Jean-Philippe Lang | |
| 282 | 54 | Jean-Philippe Lang | Example: |
| 283 | 54 | Jean-Philippe Lang | |
| 284 | 54 | Jean-Philippe Lang | <pre> |
| 285 | 54 | Jean-Philippe Lang | GET /issues/296.json |
| 286 | 54 | Jean-Philippe Lang | |
| 287 | 54 | Jean-Philippe Lang | {"issue": |
| 288 | 54 | Jean-Philippe Lang | { |
| 289 | 54 | Jean-Philippe Lang | "id":8471, |
| 290 | 54 | Jean-Philippe Lang | ... |
| 291 | 54 | Jean-Philippe Lang | "custom_fields": |
| 292 | 54 | Jean-Philippe Lang | [ |
| 293 | 54 | Jean-Philippe Lang | {"value":["1.0.1","1.0.2"],"multiple":true,"name":"Affected version","id":1}, |
| 294 | 54 | Jean-Philippe Lang | {"value":"Fixed","name":"Resolution","id":2} |
| 295 | 54 | Jean-Philippe Lang | ] |
| 296 | 54 | Jean-Philippe Lang | } |
| 297 | 54 | Jean-Philippe Lang | } |
| 298 | 54 | Jean-Philippe Lang | </pre> |