Project

General

Profile

Using RestAPI to add a relation to an issue

Added by Clément Perrod almost 11 years ago

Hello,

I am trying to create an issue with a relation in Ruby with the RestAPI.
Creating the issue following this page (http://www.redmine.org/projects/redmine/wiki/Rest_api_with_ruby) works fine but I can't get the object / syntax to add a relation.

I tried many things according to this page (http://www.redmine.org/projects/redmine/wiki/Rest_IssueRelations) like creating a Relation class from ActiveResource but all I got is either nothing or a 404 return code because the site url is wrong.

Can anyone help me?

The issue code

require 'rubygems'
require 'active_resource'

# Issue model on the client side
class Issue < ActiveResource::Base
  self.site = 'http://redmine/'
  self.user = '...'
  self.password = '...'
end

# Creating an issue
issue = Issue.new(
  :subject => 'Some subject',
  :project_id => 10,
  :tracker_id => 18,
  :custom_field_values => {'56' => '1'},
  :description => 'Some desc',  
)

if issue.save
  puts issue.id
else
  puts issue.errors.full_messages
end

The relation code I tried (where 1146 and 1121 are existing issues on my Redmine)

require 'rubygems'
require 'active_resource'

class Relation < ActiveResource::Base
  self.site = 'http://redmine/issues/1146'
  self.user = '...'
  self.password = '...'
end

relation = Relation.new(
  :issue_to_id => 1121,
  :relation_type => 'relates'
)

if relation.save
  puts relation.id
else
  puts relation.errors.full_messages
end

I also tried by adding the relation node on the issue object with no more success.