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