Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

SOAP API: Trouble creating new issue with custom fields using Ruby/Savon

Andrew Kirk January 20, 2012

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!

8 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Stefan Schiffer February 12, 2012

Hey all,

in the meantime i found the reason. In fact the error really describes what's going on. We digged more into the WSDL file and found out that the Webservice expects an array also for the Values of each custom fields. So what is working now is the following:

...
:customFieldValues => [:customFieldValue => [ { :customfieldId => "customfield_11511", :values => [ :values => [ 'to be filled' ] ] }, { :customfieldId => "customfield_11410", :values => [ :values => [ 'to be filled' ] ] }, { :customfieldId => "customfield_11514", :values => [ :values => [ issue[:impact] ] ] }

Hope this helps,

Cheers
Stefan

Andrew Kirk February 12, 2012

Awesome. Thanks for sharing this solution!

1 vote
Stefan Schiffer February 5, 2012

Hey matt,

i have the same problems. When i try to assign a customfield value the way you suggested i get the following error from JIRA:

(soapenv:Server.userException) com.atlassian.jira.rpc.exception.RemoteValidationException: Custom field ID 'null' is invalid.
Stefan Schiffer February 5, 2012

hey all,

using SoapUI i finally managed to create a new Issue through JIRA's soap API. The XML Request that has been accepted looks like this:

<customFieldValues xsi:type="jir:ArrayOf_tns1_RemoteCustomFieldValue" soapenc:arrayType="bean:RemoteCustomFieldValue[]" xmlns:jir="https://...//rpc/soap/jirasoapservice-v2">
    <customFieldValues>
        <customfieldId xsi:type="xsd:string">customfield_11511</customfieldId>
        <values xsi:type="xsd:string">myValue</values>
    </customFieldValues>
    <customFieldValues>
        <customfieldId xsi:type="xsd:string">customfield_11514</customfieldId>
        <values xsi:type="xsd:string">myValue</values>
    </customFieldValues>
</customFieldValues>

So this is what i now try to create within my Ruby on Rails application. I also use Savon to send the requests. Looking at the Request that is generated, it already has the right structure which is:

<customFieldValues>
    <customFieldValues>
        <customfieldId>customfield_11511</customfieldId>
    <values>Stefan</values>
    </customFieldValues>
    <customFieldValues>
        <customfieldId>customfield_11514</customfieldId>
    <values>16156</values>
    </customFieldValues>
</customFieldValues>

But now i get the following error: SAXException: Found character data inside an array element while deserializing

What's left is my SOAP call in Ruby which is:

requestFilter = @client.request :soap, :create_issue, body: { "in0" => @token, 
								                     "in1" =>{ :type => "68",
												   :project => "IXO", 
												   :summary => issue[:title],
												   :description => issue[:description],
												   :customFieldValues => [ {"customfieldId" => "customfield_11511", "values" => "value1"},
																      {"customfieldId" => "customfield_11514", "values" => "value1" },
																      {"customfieldId" => "customfield_11410", "values" => "value3"} ],
												   :attributes! => { :customFieldValues => { 'xsi:type' => 'jir:ArrayOf_tns1_RemoteCustomFieldValue' } }
											          } }

Cheers

Andrew Kirk February 12, 2012

Steffan,

Thanks for providing the SOAP XML request example. Like you, I tried explicity setting the attributes of the "customFieldValues" element but with no success. I still get the "SAXException: Found character data inside an array element while deserializing" error message.

0 votes
saranya velu September 30, 2012

Hi,

Below is my sample xml request to jira.

Getting error message: .xml.sax.SAXException: Found character data inside an array element while deserializing (Savon::SOAP::Fault)

<customFieldValues>
<customField>
<customfieldId>customfield_11121</customfieldId>
<values>TEST</values>
</customField>
<customField>
<customfieldId>customfield_11121</customfieldId>
<values>TESTing</values>
</customField>
</customFieldValues>

Can you please suggest me to resolve this issue.

0 votes
Firstname Lastname May 22, 2012

Thanks a lot for this reply Andrew. So is component piece working for you? What version are you using? I have tried same exact way to add components but nothing is working for me at all.

:components => {'components' => {'id' => '10786', 'name' => 'General Troubleshooting'}}

I am facing a miserable difficulty in getting component added in createIssue. This my question I asked few days back, no one seemed to know the explanation. - https://answers.atlassian.com/questions/56191/how-to-set-components-while-creating-a-new-issue-via-soap

I have tried the way showed here, and lot of other combination according to their documentation. I don't know what else to do.

http://docs.atlassian.com/rpc-jira-plugin/4.3.3/com/atlassian/jira/rpc/soap/beans/RemoteComponent.html

public class RemoteComponentextends AbstractNamedRemoteEntity

<th align="left" colspan="2">Constructor Summary</th>
RemoteComponent()
RemoteComponent(org.ofbiz.core.entity.GenericValue gv)
RemoteComponent(java.lang.String id, java.lang.String name)

0 votes
Andrew Kirk May 22, 2012

In reponse to the question immediately above regarding the way the components are defined...

:components =&gt; {'Math' =&gt; {'id' =&gt; '16420', 'name' =&gt; 'Math'}},

In order to generate the correct SOAP XML, my understanding is that the "components" object must be a hash whose values are also a hash. The keys used in that hash can be anything so long as they result in valid XML tags. I choose to set the key to whatever the name of the compontent was simply for convenience (so, in the example above, the key for the "Math" component was "Math").

Put another way, each component in the resulting SOAP XML must be wrapped in a separate node under the parent "components" node. So, for example, suppose you wanted to set two components ("Math" and "Foobar"), you might definate your compontents object as follows...

:components =&gt; {'component_1' =&gt; {'id' =&gt; '16420', 'name' =&gt; 'Math'}, "component_2" =&gt; {'id' =&gt; '16421', 'name' =&gt; "Foobar"}}

The resulting SOAP XML would be...

&lt;components&gt;
	&lt;component_1&gt;
		&lt;id&gt;16420&lt;/id&gt;
		&lt;name&gt;Math&lt;/name&gt;
	&lt;/component_1&gt;
	&lt;component_2&gt;
		&lt;id&gt;16420&lt;/id&gt;
		&lt;name&gt;Foobar&lt;/name&gt;
	&lt;/component_2&gt;
&lt;/components&gt;

Hope that helps.

0 votes
Firstname Lastname May 22, 2012

Hey Andrew, I am trying similar code in ruby and savon. I have a quick question for you. In your components what is that "Math" ('Math' =>{...}) for? I know you have same name for coponent name "Math". but I want to know what if the first one for?

0 votes
MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2012

Thought I answered this one, perhaps elsewhere? Replace

customFieldValues => [{'customfieldId' => 'customfield_11630', 'values' => ['estimate']}]
with
customFieldValues => [{'id' => 'customfield_11630', 'values' => ['estimate']}]
Andrew Kirk January 29, 2012

Matt, thanks for the response. I get the same error, however, using the change you suggested above...

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

In looking at the documentation for RemoteCustomFieldValue, it appears that "customfieldId" is the correct parameter name...

"customfieldId - The string ID of an existing custom field, of the form 'customfield_[id]' where [id] is the database ID of the custom field. This ID can be determined from the database, or by viewing a custom field in the admin interface, and copying its ID from the URL."

This makes me think that the SOAP XML that is being generated is somehow off...

<customFieldValues>
	<customfieldId>customfield_11630</customfieldId>
	<values>estimate</values>
</customFieldValues>

For example, suppose that I was trying to populate multiple custom fields. Shouldn't there be another element tag that wraps each custom field? Something like...

<customFieldValues>
	<customField>
		<customfieldId>customfield_11630</customfieldId>
		<values>estimate</values>
	</customField>
</customFieldValues>

Thanks again for the help.

0 votes
Andrew Kirk January 20, 2012

I am working with Jira v4.4.3#663-r165197

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events