Rest api » History » Version 1
Jean-Philippe Lang, 2010-01-13 20:34
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 | h2. API Description |
||
8 | |||
9 | * [[Rest_Issues|Issues]] |
||
10 | |||
11 | h2. API Usage |
||
12 | |||
13 | h3. Ruby |
||
14 | |||
15 | 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. |
||
16 | |||
17 | <pre> |
||
18 | <code class="ruby"> |
||
19 | require 'rubygems' |
||
20 | require 'active_resource' |
||
21 | |||
22 | # Issue model on the client side |
||
23 | class Issue < ActiveResource::Base |
||
24 | self.site = 'http://redmine.server/' |
||
25 | self.user = 'foo' |
||
26 | self.password = 'bar' |
||
27 | end |
||
28 | |||
29 | # Retrieving issues |
||
30 | issues = Issue.find(:all) |
||
31 | puts issues.first.subject |
||
32 | |||
33 | # Retrieving an issue |
||
34 | issue = Issue.find(1) |
||
35 | puts issue.description |
||
36 | |||
37 | # Creating an issue |
||
38 | issue = Issue.new(:subject => 'REST API', :assigned_to_id => 1, :project_id => 1) |
||
39 | if issue.save |
||
40 | puts issue.id |
||
41 | else |
||
42 | puts issue.errors.full_messages |
||
43 | end |
||
44 | |||
45 | # Updating an issue |
||
46 | issue = Issue.find(1) |
||
47 | issue.subject = 'REST API' |
||
48 | issue.save |
||
49 | |||
50 | # Deleting an issue |
||
51 | issue = Issue.find(1) |
||
52 | issue.destroy |
||
53 | </code> |
||
54 | </pre> |