Project

General

Profile

Actions

Defect #22628

closed

Create issue with custom fields with ruby API

Added by Marcin Garski about 8 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
REST API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

Hey!
I'm trying to create an issus in ruby script with one custom_field. I've created custom field (down drop list with 5 values) with web interface. I tried to do this according to wiki: Rest_api_with_ruby, but I think this wiki page is out of date. I searched for older tickets, found that 'custom_field_values' isn't used anymore, the new approach is to do this with array 'custom_fields' and by update operation (get issue by id and set values in custom_fields array).
The example given in wiki throws error:

ActiveResource::BadRequest: Failed.  Response code = 400.  Response message = Bad Reques

The best solution would be to assign the right value while creating issue (one save operation), I don't want to create it in first step, and then set the right value of custom field with update method (two save operations).

Is it possible? Please, correct the wiki page if it's deprecated.

Thx for help.
gary

Actions #1

Updated by Toshi MARUYAMA about 8 years ago

  • Description updated (diff)
Actions #2

Updated by Toshi MARUYAMA about 8 years ago

You can edit wiki Rest_api_with_ruby.

Actions #3

Updated by Marcin Garski about 8 years ago

Ok, but I haven't figured it out how should it be done. Should I use ':custom_fields' symbol while creating a new Issue?? That's my problem. :) I can't figure out the syntax.

Actions #4

Updated by Marcin Garski about 8 years ago

  • Status changed from New to Resolved

Ok, great, found solution. We need to pass array of hashes as value.

For example, we've created custom_field named "location" with 2 options (IT,office). Let's assume that redmine created this custom_field with id=2 (second custom_field in system, you can check it in your DB), so if we want to add new issue with location: IT it should be:


# Creating an issue
issue = Issue.new(
  :subject => 'REST API',
  :assigned_to_id => 1,
  :project_id => 1
  :custom_fields => [{id: 2, value: "IT"}]
)
if issue.save
  puts issue.id
else
  puts issue.errors.full_messages
end


works for me! :)

Actions #5

Updated by Toshi MARUYAMA about 8 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF