Project

General

Profile

Rest api » History » Version 4

Jean-Philippe Lang, 2010-01-14 20:55
Projects API added

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 4 Jean-Philippe Lang
_At the time of writing, the API is only available in trunk (see r3310, r3313)._
8 2 Jean-Philippe Lang
9 1 Jean-Philippe Lang
h2. API Description
10
11
* [[Rest_Issues|Issues]]
12 4 Jean-Philippe Lang
* [[Rest_Projects|Projects]]
13 1 Jean-Philippe Lang
14
h2. API Usage
15
16
h3. Ruby
17
18
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.
19
20 3 Jean-Philippe Lang
Here is a simple ruby script that demonstrates how to use the Redmine REST API:
21
22 1 Jean-Philippe Lang
<pre>
23
<code class="ruby">
24
require 'rubygems'
25
require 'active_resource'
26
27
# Issue model on the client side
28
class Issue < ActiveResource::Base
29
  self.site = 'http://redmine.server/'
30
  self.user = 'foo'
31
  self.password = 'bar'
32
end
33
34
# Retrieving issues
35
issues = Issue.find(:all)
36
puts issues.first.subject
37
38
# Retrieving an issue
39
issue = Issue.find(1)
40
puts issue.description
41 3 Jean-Philippe Lang
puts issue.author.name
42 1 Jean-Philippe Lang
43
# Creating an issue
44
issue = Issue.new(:subject => 'REST API', :assigned_to_id => 1, :project_id => 1)
45
if issue.save
46
  puts issue.id
47
else
48
  puts issue.errors.full_messages
49
end
50
51
# Updating an issue
52
issue = Issue.find(1)
53
issue.subject = 'REST API'
54
issue.save
55
56
# Deleting an issue
57
issue = Issue.find(1)
58
issue.destroy
59
</code>
60
</pre>