Rest api » History » Version 38
Jean-Philippe Lang, 2011-07-03 19:51
Authentication with Redmine-API-Key header
1 | 26 | Jean-Philippe Lang | {{>toc}} |
---|---|---|---|
2 | |||
3 | 1 | Jean-Philippe Lang | h1. Redmine API |
4 | |||
5 | Redmine exposes some of its data through a REST API. This API provides access and basic CRUD operations (create, update, delete) for the resources described below. |
||
6 | |||
7 | h2. API Description |
||
8 | |||
9 | 24 | Jean-Philippe Lang | |_.Resource |_.Status |_.Notes |_.Availability| |
10 | |[[Rest_Issues|Issues]] | Beta | Usable with some bugs and rough edges. | 1.0 | |
||
11 | |[[Rest_Projects|Projects]] | Beta | Usable with some bugs and rough edges. | 1.0 | |
||
12 | 28 | Jean-Philippe Lang | |[[Rest_Users|Users]] | Beta | | 1.1 | |
13 | |[[Rest_TimeEntries|TimeEntries]] | Beta | | 1.1 | |
||
14 | |[[Rest_News|News]] | Prototype | Prototype implementation for @index@ only | 1.1 | |
||
15 | 24 | Jean-Philippe Lang | |[[Rest_WikiPages|Wiki Pages]] | Planned | | 1.2 | |
16 | |||
17 | 15 | Eric Davis | Status legend: |
18 | 1 | Jean-Philippe Lang | |
19 | * Stable - feature complete, no major changes planned |
||
20 | * Beta - usable for integrations with some bugs or missing minor functionality |
||
21 | * Alpha - major functionality in place, needs feedback from API users and integrators |
||
22 | * Prototype - very rough implementation, possible major breaking changes mid-version. *Not recommended for integration* |
||
23 | * Planned - planned in a future version, depending on developer availability |
||
24 | |||
25 | 24 | Jean-Philippe Lang | h2. General topics |
26 | 1 | Jean-Philippe Lang | |
27 | 24 | Jean-Philippe Lang | h3. Authentication |
28 | |||
29 | Most of the time, the API requires authentication. To enable the API-style authentication, you have to check *Enable REST API* in Administration -> Settings -> Authentication. Then, authentication can be done in 2 different ways: |
||
30 | * using your regular login/password via HTTP Basic authentication. |
||
31 | 38 | Jean-Philippe Lang | * using your API key which is a handy way to avoid putting a password in a script. The API key may be attached to each request in one of the following way: |
32 | ** passed in as a "key" parameter |
||
33 | ** passed in as a username with a random password via HTTP Basic authentication |
||
34 | ** passed in as a "Redmine-API-Key" HTTP header (added in Redmine 1.1.0) |
||
35 | |||
36 | You can find your API key on your account page ( /my/account ) when logged in, on the right-hand pane of the default layout. |
||
37 | 24 | Jean-Philippe Lang | |
38 | h3. Collection resources and pagination |
||
39 | |||
40 | The response to a GET request on a collection ressources (eg. @/issues.xml@, @/users.xml@) generally won't return all the objets available in your database. Redmine version:1.1.0 introduces a common way to query such ressources using the following parameters: |
||
41 | |||
42 | * @offset@: the offset of the first object to retrieve |
||
43 | * @limit@: the number of items to be present in the response (default is 25, maximum is 100) |
||
44 | |||
45 | 25 | Jean-Philippe Lang | Alternatively, you can use the @page@ parameter, instead of @offset@, in conjunction with @limit@. |
46 | 24 | Jean-Philippe Lang | |
47 | Examples: |
||
48 | |||
49 | <pre> |
||
50 | GET /issues.xml |
||
51 | => returns the 25 first issues |
||
52 | |||
53 | GET /issues.xml?limit=100 |
||
54 | => returns the 100 first issues |
||
55 | |||
56 | GET /issues.xml?offset=30&limit=10 |
||
57 | => returns 10 issues from the 30th |
||
58 | |||
59 | GET /issues.xml?page=3&limit=10 |
||
60 | => same as above |
||
61 | </pre> |
||
62 | |||
63 | Responses to GET requests on collection ressources provide information about the total object count available in Redmine and the offset/limit used for the response. Examples: |
||
64 | |||
65 | <pre> |
||
66 | GET /issues.xml |
||
67 | |||
68 | <issues type="array" total_count="2595" limit="25" offset="0"> |
||
69 | ... |
||
70 | </issues> |
||
71 | </pre> |
||
72 | |||
73 | <pre> |
||
74 | GET /issues.json |
||
75 | |||
76 | { "issues":[...], "total_count":2595, "limit":25, "offset":0 } |
||
77 | </pre> |
||
78 | |||
79 | Note: if you're using a REST client that does not support such top level attributes (total_count, limit, offset), you can set the @nometa@ parameter or @X-Redmine-Nometa@ HTTP header to 1 to get responses without them. Example: |
||
80 | |||
81 | <pre> |
||
82 | GET /issues.xml?nometa=1 |
||
83 | |||
84 | <issues type="array"> |
||
85 | ... |
||
86 | </issues> |
||
87 | </pre> |
||
88 | 23 | Jean-Philippe Lang | |
89 | 29 | Etienne Massip | h3. Fetching associated data |
90 | |||
91 | Since of version:1.1.0, you have to explicitly specify the associations you want to be included in the query result by appending the @include@ parameter to the query url : |
||
92 | |||
93 | Example: |
||
94 | |||
95 | To retrieve issue journals with its description : |
||
96 | |||
97 | <pre> |
||
98 | GET /issues/296.xml?include=journals |
||
99 | |||
100 | <issue> |
||
101 | <id>296</id> |
||
102 | 30 | Etienne Massip | ... |
103 | 29 | Etienne Massip | <journals type="array"> |
104 | ... |
||
105 | </journals> |
||
106 | </issue> |
||
107 | </pre> |
||
108 | |||
109 | 1 | Jean-Philippe Lang | h2. API Usage in various languages/tools |
110 | 5 | Jean-Philippe Lang | |
111 | 1 | Jean-Philippe Lang | * [[Rest_api_with_ruby|Ruby]] |
112 | * [[Rest_api_with_php|PHP]] |
||
113 | 23 | Jean-Philippe Lang | * [[Rest_api_with_python|Python]] |
114 | 27 | Jean-Philippe Lang | * [[Rest_api_with_java|Java]] |
115 | 1 | Jean-Philippe Lang | * [[Rest_api_with_curl|cURL]] |
116 | 37 | Bevan Rudge | * "Drupal Redmine API module, 2.x branch (currently not stable)":http://drupal.org/project/redmine |