Project

General

Profile

Rest api » History » Version 52

Jean-Philippe Lang, 2011-11-20 17:40
API addition for issue categories

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