Project

General

Profile

Rest api » History » Version 3

Jean-Philippe Lang, 2010-01-13 21:15

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 3 Jean-Philippe Lang
Here is a simple ruby script that demonstrates how to use the Redmine REST API:
20
21 1 Jean-Philippe Lang
<pre>
22
<code class="ruby">
23
require 'rubygems'
24
require 'active_resource'
25
26
# Issue model on the client side
27
class Issue < ActiveResource::Base
28
  self.site = 'http://redmine.server/'
29
  self.user = 'foo'
30
  self.password = 'bar'
31
end
32
33
# Retrieving issues
34
issues = Issue.find(:all)
35
puts issues.first.subject
36
37
# Retrieving an issue
38
issue = Issue.find(1)
39
puts issue.description
40 3 Jean-Philippe Lang
puts issue.author.name
41 1 Jean-Philippe Lang
42
# Creating an issue
43
issue = Issue.new(:subject => 'REST API', :assigned_to_id => 1, :project_id => 1)
44
if issue.save
45
  puts issue.id
46
else
47
  puts issue.errors.full_messages
48
end
49
50
# Updating an issue
51
issue = Issue.find(1)
52
issue.subject = 'REST API'
53
issue.save
54
55
# Deleting an issue
56
issue = Issue.find(1)
57
issue.destroy
58
</code>
59
</pre>