Redmine REST API » 履歴 » バージョン 1
Mitsuyoshi Yoshida, 2011/11/13 12:07
1 | 1 | Mitsuyoshi Yoshida | Redmine では REST API が提供されています。 |
---|---|---|---|
2 | この API を使って Redmine 上のデータにアクセスすることができ、 CRUD(Create, Read, Update, Delete) と呼ばれる 作成、読み取り、更新、削除 といった基本的な操作を行うことが出来ます。 |
||
3 | API が用意されているデータには以下の表のものがあります。 |
||
4 | |||
5 | |_. データ |_.ステータス |_.注意点 |_.Redmine バージョン| |
||
6 | |[[Rest_Issues|チケット]] | Beta | 荒削りの段階でまだバグが残っています | 1.0 | |
||
7 | |[[Rest_Projects|プロジェクト]] | Beta | 荒削りの段階でまだバグが残っています | 1.0 | |
||
8 | |[[Rest_Users|ユーザー]] | Beta | | 1.1 | |
||
9 | |[[Rest_TimeEntries|作業時間]] | Beta | | 1.1 | |
||
10 | |[[Rest_News|News]] | Prototype | @index@ だけの試験的な実装です | 1.1 | |
||
11 | |[[Rest_IssueRelations|Issue Relations]] | Alpha | | 1.3 | |
||
12 | |[[Rest_Versions|Versions]] | Alpha | | 1.3 | |
||
13 | |[[Rest_Queries|Queries]] | Alpha | | 1.3 | |
||
14 | |[[Rest_Attachments|Attachments]] | Alpha | | 1.3 | |
||
15 | |||
16 | ステータスの凡例 : |
||
17 | |||
18 | * Stable - 仕様機能は完成されていて、今後の大きな変更は予定されていません。 |
||
19 | * Beta - まだバグが残っているか、いくつかの細かな機能が実装されていません。 |
||
20 | * Alpha - 主要な機能は出来てますが、まだ API 使用者からのフィードバッグを必要としています。 |
||
21 | * Prototype - 試験的な運用のためにざっと実装されただけで、今後大きな変更が加わる可能性があります。 *本格的に使用するのはお勧めできません* |
||
22 | * Planned - 将来のバージョンで予定されているもので、いつになるかは開発参加者によって変わってきます。 |
||
23 | |||
24 | |||
25 | h2. 各データ共通 |
||
26 | |||
27 | h3. ユーザー認証 |
||
28 | |||
29 | ほとんどの場合、 API では認証を必要とします。 |
||
30 | |||
31 | API 型式での認証を可能にするためには |
||
32 | _管理_ → _設定_ → _認証_ の順で設定ページを表示した後、 |
||
33 | *[REST による Web サービスを有効にする]* にチェックを入れます。 |
||
34 | |||
35 | !auth_settings.png! |
||
36 | |||
37 | そうすると普段のログイン名とパスワードを使用した HTTP 認証方法の他に API キーを使った認証が利用できるようになります。 API キーを使うとスクリプト中にパスワードを記述を避けることが簡単に出来ます。 |
||
38 | |||
39 | 次の方法で各リクエストに対して API キーを付けることが可能です。 |
||
40 | * "key" パラメーター |
||
41 | * 基本的な HTTP 認証でのランダムなパスワードのユーザー |
||
42 | * "X-Redmine-API-Key" の HTTP ヘッダ (Redmine 1.1.0 で追加) |
||
43 | |||
44 | 自分の API キーを知りたい場合には、ログイン後、 [個人設定](/my/account)ページを開き、ページの右側(デフォルトテーマの場合)を見て下さい。 |
||
45 | |||
46 | !api_key.png! |
||
47 | |||
48 | |||
49 | h3. データリストの取得とページ割り |
||
50 | |||
51 | データリストを取得する GET リクエスト(@/issues.xml@, @/users.xml@ など)では、通常データベース内の利用可能な全てのデータが一度に返ってくるわけではありません。 |
||
52 | Redmine のバージョン 1.1.0 以降ではデータを要求する各リクエストに対して次のパラメータが共通して使用できるようになっています。 |
||
53 | |||
54 | * @offset@: データ取得の開始位置 |
||
55 | * @limit@: 取得するデータ数 (デフォルトは 25 で、 最大が 100) |
||
56 | |||
57 | @offset@ の代わりに、 @limit@ と併用して @page@ パラメーターを使用することも出来ます。 |
||
58 | |||
59 | +例+: |
||
60 | |||
61 | <pre> |
||
62 | GET /issues.xml |
||
63 | => 最初の 25 チケットが返ってきます |
||
64 | |||
65 | GET /issues.xml?limit=100 |
||
66 | => 最初の 100 チケットが返ってきます |
||
67 | |||
68 | GET /issues.xml?offset=30&limit=10 |
||
69 | => 30 番目からの 10 チケットが返ってきます |
||
70 | |||
71 | GET /issues.xml?page=3&limit=10 |
||
72 | => 前のリクエストと同じです |
||
73 | </pre> |
||
74 | |||
75 | データ一覧の GET リクエストから返ってくるレスポンス情報の中には利用可能な全データの要素数や使用した @offset/limit@ の値が含まれています。 |
||
76 | +例(XML)+: |
||
77 | <pre> |
||
78 | GET /issues.xml |
||
79 | </pre><pre><code class="xml"> |
||
80 | <issues type="array" total_count="2595" limit="25" offset="0"> |
||
81 | ... |
||
82 | </issues> |
||
83 | </code></pre> |
||
84 | |||
85 | +例(JSON)+: |
||
86 | |||
87 | <pre> |
||
88 | GET /issues.json |
||
89 | </pre><pre><code class="json"> |
||
90 | { "issues":[...], "total_count":2595, "limit":25, "offset":0 } |
||
91 | </code></pre> |
||
92 | |||
93 | *注意*: トップレベルにある total_count, limit, offset といった属性に対して、使用している REST クライアントが対応していない場合には @nometa@ パラメーターか @X-Redmine-Nometa@ の HTTP ヘッダのどちらかを設定すれば、属性を除いた応答が返ってきます。 |
||
94 | |||
95 | <pre> |
||
96 | GET /issues.xml?nometa=1 |
||
97 | </pre><pre><code class="xml"> |
||
98 | <issues type="array"> |
||
99 | ... |
||
100 | </issues> |
||
101 | </code></pre> |
||
102 | |||
103 | |||
104 | h3. 関連データの取得 |
||
105 | |||
106 | バージョン 1.1.0 以降、関連データを含んだ検索結果を得たい場合には、 URL に @include@ パラメーターを付けて、明示的に指定する必要があります。 |
||
107 | |||
108 | +例+: チケット履歴(journals)の記述を取得 |
||
109 | |||
110 | <pre> |
||
111 | GET /issues/296.xml?include=journals |
||
112 | </pre><pre><code class="xml"> |
||
113 | <issue> |
||
114 | <id>296</id> |
||
115 | ... |
||
116 | <journals type="array"> |
||
117 | ... |
||
118 | </journals> |
||
119 | </issue> |
||
120 | </code></pre> |
||
121 | |||
122 | 複数の関連データを得たい場合にはカンマで区切って指定します。 |
||
123 | |||
124 | +例+: |
||
125 | |||
126 | <pre> |
||
127 | GET /issues/296.xml?include=journals,changesets |
||
128 | </pre><pre><code class="xml"> |
||
129 | <issue> |
||
130 | <id>296</id> |
||
131 | ... |
||
132 | <journals type="array"> |
||
133 | ... |
||
134 | </journals> |
||
135 | <changesets type="array"> |
||
136 | ... |
||
137 | </changesets> |
||
138 | </issue> |
||
139 | </code></pre> |
||
140 | |||
141 | |||
142 | h3. カスタムフィールドがある場合 |
||
143 | |||
144 | Redmine のほとんどのデータではカスタムフィールドを使用することが出来ます。 |
||
145 | このカスタムフィールドの値は @custom_fields@ 要素に記述されています。 |
||
146 | |||
147 | +例(XML)+: |
||
148 | |||
149 | <pre> |
||
150 | GET /issues/296.xml # an issue with 2 custom fields |
||
151 | </pre><pre><code class="xml"> |
||
152 | <issue> |
||
153 | <id>296</id> |
||
154 | ... |
||
155 | <custom_fields type="array"> |
||
156 | <custom_field name="Affected version" id="1"> |
||
157 | <value>1.0.1</value> |
||
158 | </custom_field> |
||
159 | <custom_field name="Resolution" id="2"> |
||
160 | <value>Fixed</value> |
||
161 | </custom_field> |
||
162 | </custom_fields> |
||
163 | </issue> |
||
164 | </code></pre> |
||
165 | |||
166 | +例(JSON)+: |
||
167 | |||
168 | <pre> |
||
169 | GET /issues/296.json # an issue with 2 custom fields |
||
170 | </pre><pre><code class="json"> |
||
171 | {"issue": |
||
172 | { |
||
173 | "id":8471, |
||
174 | ... |
||
175 | "custom_fields": |
||
176 | [ |
||
177 | {"value":"1.0.1","name":"Affected version","id":1}, |
||
178 | {"value":"Fixed","name":"Resolution","id":2} |
||
179 | ] |
||
180 | } |
||
181 | } |
||
182 | </code></pre> |
||
183 | |||
184 | データの作成や更新時にカスタムフィールドの値も一緒に設定や変更をしたい場合には、どちらも同じ文法で記述できます(カスタムフィールドの名前を必要としない場合を除く)。 |
||
185 | |||
186 | +例(XML)+: |
||
187 | |||
188 | <pre> |
||
189 | PUT /issues/296.xml |
||
190 | </pre><pre><code class="xml"> |
||
191 | <issue> |
||
192 | <subject>Updating custom fields of an issue</subject> |
||
193 | ... |
||
194 | <custom_fields type="array"> |
||
195 | <custom_field id="1"> |
||
196 | <value>1.0.2</value> |
||
197 | </custom_field> |
||
198 | <custom_field id="2"> |
||
199 | <value>Invalid</value> |
||
200 | </custom_field> |
||
201 | </custom_fields> |
||
202 | </issue> |
||
203 | </code></pre> |
||
204 | |||
205 | *注意*: @custom_fields@ の XML タグにある @type="array"@ 属性は必ず付ける必要があります。 |
||
206 | |||
207 | |||
208 | +例(JSON)+: |
||
209 | |||
210 | <pre> |
||
211 | PUT /issues/296.json |
||
212 | </pre><pre><code class="json"> |
||
213 | {"issue": |
||
214 | { |
||
215 | "subject":"Updating custom fields of an issue", |
||
216 | ... |
||
217 | "custom_fields": |
||
218 | [ |
||
219 | {"value":"1.0.2","id":1}, |
||
220 | {"value":"Invalid","id":2} |
||
221 | ] |
||
222 | } |
||
223 | } |
||
224 | </code></pre> |
||
225 | |||
226 | |||
227 | h2. 種々の言語やツールでの API の使用法 |
||
228 | |||
229 | * [[Rest_api_with_ruby|Ruby]] |
||
230 | * [[Rest_api_with_php|PHP]] |
||
231 | * [[Rest_api_with_python|Python]] |
||
232 | * [[Rest_api_with_java|Java]] |
||
233 | * [[Rest_api_with_curl|cURL]] |
||
234 | * "Drupal Redmine API module, 2.x branch (currently not stable)":http://drupal.org/project/redmine |
||
235 | * [[Rest_api_with_csharp|.NET]] |
||
236 | * [[Rest_api_with_delphi|Delphi]] |