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