プロジェクト

全般

プロフィール

Rest api with curl » 履歴 » バージョン 2

Mitsuyoshi Yoshida, 2011/11/15 23:44

1 1 Mitsuyoshi Yoshida
redmine.org の "Rest_api_with_curl":http://www.redmine.org/projects/redmine/wiki/Rest_api_with_curl の日本語訳です。
2
3
h1. cURL での REST API の使用法
4
5
"cURL":http://curl.haxx.se/ はいろんなプロトコルに対応したデータ通信用のコマンドラインツールです。 これを Redmine REST API でのやりとりに使うことが出来ます。
6
7
+JSON を使用+
8
9
以下の例はチケットを更新するコマンドの簡単な使用例です。
10
11
<pre>
12
curl -v -H "Content-Type: application/json" -X PUT --data "@388.json" -u login:password http://redmine/issues/388.json
13
</pre>
14
15
Redmine に送る @388.json@ ファイルの内容は次のようになっています。
16
17
<pre><code class="json">
18
{
19
  "issue": {
20
    "subject": "subject123",
21
    "notes": "Changing the subject"
22
  }
23
}
24
</code></pre>
25
26
27
*注意*: 送信するデータのフォーマットにあわせて、 @Content-Type@ ヘッダー を設定する必要があります。
28
次の値のうちのどちらかを必ず指定して下さい。
29
30
* @application/json@
31
* @application/xml@
32
33
34
+XML を使用+
35
36 2 Mitsuyoshi Yoshida
次の例ではカスタムフィールドを持ったチケットを作成しています。
37 1 Mitsuyoshi Yoshida
38
<pre>
39
curl -v -H "Content-Type: application/xml" -X POST --data "@issue.xml" -u login:password http://redmine/issues.xml
40
</pre>
41
42
@issue.xml@ の中身は以下のものです。
43
44
<pre><code class="xml">
45
<?xml version="1.0" encoding="ISO-8859-1" ?>
46
<issue>
47
  <subject>API custom fields</subject>
48
  <project_id>1</project_id>
49
  <tracker_id>2</tracker_id>
50
  <custom_fields type="array">
51
    <custom_field>
52
      <id>2</id>
53
      <value>Fixed</value>
54
    </custom_field>
55
    <custom_field>
56
      <id>1</id>
57
      <value>0.8.2</value>
58
    </custom_field>
59
  </custom_fields>
60
</issue>
61
</code></pre>