Rest api » History » Version 2
Jean-Philippe Lang, 2010-01-13 20:36
1 | 1 | Jean-Philippe Lang | h1. Redmine API |
---|---|---|---|
2 | |||
3 | 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. |
||
4 | |||
5 | Most of the time, the API requires authentication. This is done via HTTP Basic authentication using the regular Redmine accounts. To enable this API-style authentication, check *Enable REST API* in Administration -> Settings -> Authentication. |
||
6 | |||
7 | 2 | Jean-Philippe Lang | _At the time of writing, the API is only available in trunk (see r3310)._ |
8 | |||
9 | 1 | Jean-Philippe Lang | h2. API Description |
10 | |||
11 | * [[Rest_Issues|Issues]] |
||
12 | |||
13 | h2. API Usage |
||
14 | |||
15 | h3. Ruby |
||
16 | |||
17 | Redmine REST API follows the Rails's RESTful conventions, so using it with "ActiveResource":http://api.rubyonrails.org/classes/ActiveResource/Base.html is pretty straightforward. |
||
18 | |||
19 | <pre> |
||
20 | <code class="ruby"> |
||
21 | require 'rubygems' |
||
22 | require 'active_resource' |
||
23 | |||
24 | # Issue model on the client side |
||
25 | class Issue < ActiveResource::Base |
||
26 | self.site = 'http://redmine.server/' |
||
27 | self.user = 'foo' |
||
28 | self.password = 'bar' |
||
29 | end |
||
30 | |||
31 | # Retrieving issues |
||
32 | issues = Issue.find(:all) |
||
33 | puts issues.first.subject |
||
34 | |||
35 | # Retrieving an issue |
||
36 | issue = Issue.find(1) |
||
37 | puts issue.description |
||
38 | |||
39 | # Creating an issue |
||
40 | issue = Issue.new(:subject => 'REST API', :assigned_to_id => 1, :project_id => 1) |
||
41 | if issue.save |
||
42 | puts issue.id |
||
43 | else |
||
44 | puts issue.errors.full_messages |
||
45 | end |
||
46 | |||
47 | # Updating an issue |
||
48 | issue = Issue.find(1) |
||
49 | issue.subject = 'REST API' |
||
50 | issue.save |
||
51 | |||
52 | # Deleting an issue |
||
53 | issue = Issue.find(1) |
||
54 | issue.destroy |
||
55 | </code> |
||
56 | </pre> |