Jira SOAP API:使用 Ruby/Savon 创建自定义字段的新问题时遇到问题

发布于 2024-12-28 07:18:54 字数 2752 浏览 0 评论 0原文

背景:我正在尝试创建一个相对简单的 Ruby 脚本来在 Jira 实例中创建问题。我正在使用 Savon gem (http://savonrb.com/) 来创建 SOAP 服务。

问题:当尝试创建包含自定义字段的问题时,我收到以下异常...

com.atlassian.jira.rpc.exception.RemoteValidationException: Custom field ID 'null' is invalid.

代码:

require 'savon'

# Config
host = 'myjira.com'
username = 'myUsername'
password = 'myPassword'
project = 'myProject'

# Create soap client
 client = Savon::Client.new('http://' + host + '/rpc/soap/jirasoapservice-v2?wsdl')

# Get a token
login = client.request(:login) do |soap|
  soap.body = {
    :in0 => username,
    :in1 => password
  }
end
login = login.to_hash
token = login[:login_response][:login_return]

# Create issue
create_issue = client.request(:create_issue) do |soap|
  soap.body = {
    :in0 => token,
    :in1 => {
      :type => "1",
      :project => project,
      :summary => "Jira SOAP API Test #1",
      :description => "This slip was created using Jira's SOAP API",
      :components => {'Math' => {'id' => '16420', 'name' => 'Math'}},
      :customFieldValues => [{'customfieldId' => 'customfield_11630', 'values' => ['estimate']}]
    }
  }
end

SOAP REQUEST XML:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://10.160.100.25:8080/rpc/soap/jirasoapservice-v2" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://beans.soap.rpc.jira.atlassian.com" xmlns:ins1="http://exception.rpc.jira.atlassian.com" xmlns:ins2="http://10.160.100.25:8080/rpc/soap/jirasoapservice-v2">
    <env:Body>
        <createIssue>
            <in0>xlGKWgZ85C</in0>
            <in1>
                <type>1</type>
                <project>BSA</project>
                <summary>Jira SOAP API Test #1</summary>
                <description>This slip was created using Jira's SOAP API</description>
                <components>
                    <Math>
                        <id>16420</id>
                        <name>Math</name>
                    </Math>
                </components>
                <customFieldValues>
                    <customfieldId>customfield_11630</customfieldId>
                    <values>estimate</values>
                </customFieldValues>
            </in1>
        </createIssue>
    </env:Body>
</env:Envelope>

关于我在这里可能做错了什么有什么想法吗?如果任何人都可以提供 SOAP XML 的工作示例来创建自定义字段的问题,那将非常有帮助。提前致谢!

BACKGROUND: I am attempting to create a relatively simple Ruby script to create issues in a Jira instance. I am using the Savon gem (http://savonrb.com/) to create the SOAP service.

ISSUE: When attempting to create an an issue that includes a custom field, I am getting the following exception...

com.atlassian.jira.rpc.exception.RemoteValidationException: Custom field ID 'null' is invalid.

CODE:

require 'savon'

# Config
host = 'myjira.com'
username = 'myUsername'
password = 'myPassword'
project = 'myProject'

# Create soap client
 client = Savon::Client.new('http://' + host + '/rpc/soap/jirasoapservice-v2?wsdl')

# Get a token
login = client.request(:login) do |soap|
  soap.body = {
    :in0 => username,
    :in1 => password
  }
end
login = login.to_hash
token = login[:login_response][:login_return]

# Create issue
create_issue = client.request(:create_issue) do |soap|
  soap.body = {
    :in0 => token,
    :in1 => {
      :type => "1",
      :project => project,
      :summary => "Jira SOAP API Test #1",
      :description => "This slip was created using Jira's SOAP API",
      :components => {'Math' => {'id' => '16420', 'name' => 'Math'}},
      :customFieldValues => [{'customfieldId' => 'customfield_11630', 'values' => ['estimate']}]
    }
  }
end

SOAP REQUEST XML:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://10.160.100.25:8080/rpc/soap/jirasoapservice-v2" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://beans.soap.rpc.jira.atlassian.com" xmlns:ins1="http://exception.rpc.jira.atlassian.com" xmlns:ins2="http://10.160.100.25:8080/rpc/soap/jirasoapservice-v2">
    <env:Body>
        <createIssue>
            <in0>xlGKWgZ85C</in0>
            <in1>
                <type>1</type>
                <project>BSA</project>
                <summary>Jira SOAP API Test #1</summary>
                <description>This slip was created using Jira's SOAP API</description>
                <components>
                    <Math>
                        <id>16420</id>
                        <name>Math</name>
                    </Math>
                </components>
                <customFieldValues>
                    <customfieldId>customfield_11630</customfieldId>
                    <values>estimate</values>
                </customFieldValues>
            </in1>
        </createIssue>
    </env:Body>
</env:Envelope>

Any ideas on what I might be doing wrong here? If anyone could provide a working example of a SOAP XML to create an issue with custom fields, that would be extemely helpful. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文