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