Rest api » History » Version 1

Jean-Philippe Lang, 2010-01-13 20:34

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