Rest api with curl » History » Version 3
Jean-Philippe Lang, 2011-07-03 19:55
XML example with custom fields
1 | 1 | Jean-Philippe Lang | h1. Using the REST API with cURL |
---|---|---|---|
2 | |||
3 | "curl":http://curl.haxx.se/ is a command-line tool for transferring data using various protocols. It can be used to interact with the Redmine REST API. |
||
4 | |||
5 | 3 | Jean-Philippe Lang | h2. Using JSON |
6 | |||
7 | 1 | Jean-Philippe Lang | Here is a simple example of a command that can be used to update an issue: |
8 | |||
9 | <pre> |
||
10 | 3 | Jean-Philippe Lang | curl -v -H "Content-Type: application/json" -X PUT --data "@388.json" -u login:password http://redmine/issues/388.json |
11 | 1 | Jean-Philippe Lang | </pre> |
12 | |||
13 | The file that contains the data sent to Redmine (388.json in the example above) would look like this: |
||
14 | |||
15 | <pre> |
||
16 | { |
||
17 | "issue": { |
||
18 | "subject": "subject123", |
||
19 | "notes": "Changing the subject" |
||
20 | } |
||
21 | } |
||
22 | </pre> |
||
23 | 2 | Jean-Philippe Lang | |
24 | Note: it's required to set the @Content-Type@ header according to the format of the data you are sending. It must be set to one the following values: |
||
25 | * @application/json@ |
||
26 | 1 | Jean-Philippe Lang | * @application/xml@ |
27 | 3 | Jean-Philippe Lang | |
28 | h2. Using XML |
||
29 | |||
30 | |||
31 | Here is a simple example of a command that can be used to create an issue with custom fields: |
||
32 | |||
33 | <pre> |
||
34 | curl -v -H "Content-Type: application/xml" -X POST --data "@issue.xml" -u login:password http://redmine/issues.xml |
||
35 | </pre> |
||
36 | |||
37 | Where issue.xml content is: |
||
38 | |||
39 | <pre> |
||
40 | <?xml version="1.0" encoding="ISO-8859-1" ?> |
||
41 | <issue> |
||
42 | <subject>API custom fields</subject> |
||
43 | <project_id>1</project_id> |
||
44 | <tracker_id>2</tracker_id> |
||
45 | <custom_fields type="array"> |
||
46 | <custom_field> |
||
47 | <id>2</id> |
||
48 | <value>Fixed</value> |
||
49 | </custom_field> |
||
50 | <custom_field> |
||
51 | <id>1</id> |
||
52 | <value>0.8.2</value> |
||
53 | </custom_field> |
||
54 | </custom_fields> |
||
55 | </issue> |
||
56 | </pre> |