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