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