Jira API |错误:"操作值必须是字符串" - 尝试设置嵌套两个级别的值

时间:2018-04-11 00:55:10

标签: json ruby hash nested jira-rest-api

尝试创建特定requestType的新jira票证,但它嵌套了两层深度。尝试了几个可能的改动,但没有运气。这是我的代码,

require 'jira-ruby' # https://github.com/sumoheavy/jira-ruby

options = {
            :username => jira_username,
            :password => jira_password,
            :site     => 'https://jiraurl/rest/api/2/',
            :context_path => '',
            :auth_type => :basic,
            :read_timeout => 120
          }

client = JIRA::Client.new(options)
issue = client.Issue.build
fields_options = { 
  "fields" => 
  {
    "summary"   => "Test ticket creation",
    "description" => "Ticket created from Ruby",
    "project"   => {"key" => "AwesomeProject"},
    "issuetype" => {"name" => "Task"},
    "priority" => {"name" => "P1"},
    "customfield_23070" => 
    {
      "requestType" => {
        "name" => "Awesome Request Type"
      }
    }
  }
}
issue.save(fields_options)

"errors"=>{"customfield_23070"=>"Operation value must be a string"}

还尝试将JSON对象传递给customfield_23070"customfield_23070": { "requestType": { "name": "Awesome Request Type" } } 仍然没有运气,得到相同的错误信息。

如果它有帮助,这就是我们Jira中customfield_23070的样子, enter image description here

有人知道在这种情况下如何设置requestType吗?非常感谢任何帮助!!

4 个答案:

答案 0 :(得分:0)

我不确定,但你可以试试这个可能的例子:

eg.1:

"customfield_23070"=>{"name"=>"requestType","value"=>"Awesome Request Type"}

eg.2:

"customfield_23070"=>{"requestType"=>"Awesome Request Type"}

eg.3:

"customfield_23070"=>{"value"=>"Awesome Request Type"}

eg.4

"customfield_23070"=>{"name"=>"Awesome Request Type"}

答案 1 :(得分:0)

对于具有特定数据类型(字符串/数字)的自定义字段,您必须将值传递为:

"customfield_1111": 1

或:

"customfield_1111": "string"

而不是:

"customfield_1111":{ "value": 1 }

或:

"customfield_1111":{ "value": "string" }

答案 2 :(得分:0)

对于ref,有2种方法,具体取决于您与之交互的字段

在这里看看' updating-an-issue-via-the-jira-rest-apis-6848604 '表示通过动词操作进行更新的适用字段,其他字段则可以使用上述示例, 您可以在同一调用中使用这两种方法

{
 "update": {"description": [{"set": "Description by API Update - lets do this thing"}]},
 "fields": {"customfield_23310": "TESTING0909"}
}

答案 3 :(得分:0)

好的,我想我找到了方法。

您需要提供一个字符串,该字符串是 RequestType 的 GUID。

为了获得那个 GUID。您需要在 scriptrunner 控制台中运行以下命令:

import com.atlassian.jira.component.ComponentAccessor
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ISSUE-400546") //Issue with the desired Request Type
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Tipo de solicitud del cliente") //Change it to the name of your request type field
issue.getCustomFieldValue(cf)

来源:https://community.atlassian.com/t5/Jira-Software-questions/how-to-set-request-type-value-in-while-create-jira-issue/qaq-p/1106696