1

我正在尝试使用他们的 API 创建一个发布问题以进行 redmine。他们说我应该使用这种格式。

http://www.redmine.org/projects/redmine/wiki/Rest_api_with_ruby

这是我的代码。

issue = Issue.new(
  :subject => 'Feedback',
  :assigned_to_id => 1,
  :project_id => 1,
  :description => $description,
  :custom_field_values => {"6" => "Thomas"},
)

除了最后一个名为 :custom_field_values 的字段外,所有字段都可以正常工作。运行脚本时它不会添加自定义字段

当我检查服务器日志时,发布请求将 custom_field_values 显示为 custom_field_values 的键,这会阻止我的导入工作

这是服务器日志

Parameters: {"issue"=>{"assigned_to_id"=>1, "custom_field_values"=>
{"custom_field_values"=>{"6"=>"Thomas"}}, "description"=>"placeholder text", 
"project_id"=>1, "subject"=>" Feedback"}}

当我通过 redmine 界面创建票证时,正确的 JSON 看起来像这样。

Parameters: {"utf8"=>"✓", "issue"=>{"is_private"=>"0", "tracker_id"=>"4",  
"subject"=>"test", "description"=>"test", "status_id"=>"1", "priority_id"=>"4", 
"assigned_to_id"=>"", "custom_field_values"=>{"3"=>"Web", "4"=>["Search", ""], 
"5"=>"testeaf", "6"=>"sdfasdfadf", "7"=>"2014-09-30"}}, "commit"=>"Create", 
"project_id"=>"testproject"}

谁能帮我看看为什么我会通过嵌套得到那个重复的键?如果我组成一个随机密钥,也会发生同样的事情。

我正在使用 Bitnami Redmine 2.5 Ruby 2.0 Windows 7

需要“rubygems”需要“active_resource”需要“roo”

4

2 回答 2

0

我意识到自定义字段的 active_resource 中有一些错误。因此,我决定使用 NET::HTTP 直接将我的 post 请求作为 json 对象发送,而不是使用它来发送请求。

@user = 'admin'
@pass = 'admin'
@host = 'localhost'
@port = '80'

@payload ={ 
    "issue" => {
    "project_id" => "test_project",
    "subject"=> "test subject",
    "priority_id"=> 4,
    "tracker_id"=> 4,
    "description" => "message",
    "custom_fields"=> [
        {"value"=> name, "id"=> 6},
        {"value"=> date, "id"=> 7},
        {"value"=> email, "id"=> 5}
    ]
  }
  }.to_json

def post
     req = Net::HTTP::Post.new(@post_ws, initheader = {'Content-Type' =>'application/json'})
          req.basic_auth @user, @pass
          req.body = @payload
          response = Net::HTTP.new(@host, @port).start {|http| http.request(req) }
           puts "Response #{response.code} #{response.message}:
          #{response.body}"
        end

thepost = post

遵循此处看到的模式: https ://www.socialtext.net/open/very_simple_rest_in_ruby_part_3_post_to_create_a_new_workspace

Ruby 发送 JSON 请求

于 2014-09-29T16:25:50.617 回答
0

它应该是custom_field_values,而不是custom_fields_values(单数field)。

于 2014-09-23T16:45:07.827 回答