J Tricks - Little JIRA Tricks
 
Creating an Issue in JIRA from other applications, like custom built UI for instance, is a common behaviour. It is pretty easy because JIRA provides us with the SOAP or XML/RPC interfaces. SOAP is recommended as it supports more operations which you might be using along with the Create!

Creating a JIRA SOAP client is pretty easy and is detailed in my previous tutorial. I am going to assume that you have the client created and a sample test done to ensure you are connected to your JIRA.
The first step is to create a SOAP Session and get the authentication token by logging in using the SOAP method login. Again, please refer to the source code at the end of the tutorial or to my previous post on how to do that!

Before we proceed, let us have a quick look at the createIssue method in the SOAP API . As you can see, it accepts the token and a RemoteIssue object. The latter should be populated with all the necessary things needed for you issue, at-least all the mandatory fields!

This is how we populate the RemoteIssue:

RemoteIssue issue = new RemoteIssue();
issue.setProject(PROJECT_KEY);
issue.setType(ISSUE_TYPE_ID);

issue.setSummary("Test Issue via J Tricks tutorial");

That should be the bare minimum unless you have some other fields set as mandatory. You can now invoke the createIssue method as follows:

RemoteIssue createdIssue = jiraSoapService.createIssue(authToken, issue);
System.out.println("\tSuccessfully created issue " + createdIssue.getKey());

The method accepts the RemoteIssue object we just created and returns a RemoteIssue for further processing or verification. In real life, you might need to add a lot more to the issue like 'Fix for versions' and 'Components'. Here is how we do that:

// Add remote compoments - Should be an array of RemoteComponent
RemoteComponent component = new RemoteComponent();
component.setId(COMPONENT_ID);
issue.setComponents(new RemoteComponent[] { component });

// Add remote versions - Should be an array of RemoteVersion
RemoteVersion version = new RemoteVersion();
version.setId(VERSION_ID);
issue.setFixVersions(new RemoteVersion[] { version });

Remember, the COMPONENT_ID and VERSION_ID should be the database unique ids and not name. You can find this in the URL while you are editing them or just by hovering over the action link.

If you need to apply a security level for the issue, you need to use the createIssueWithSecurityLevel method where you need to pass an additional parameter for the securityLevel.

May be one thing worth mentioning here! For the status, you shouldn't directly set it. Instead use the progressWorkflowAction method whcih we can look at at a later time.

That is it! We have the code for creating an issue via SOAP using the standard JIRA fields. Custom fields are not hard but it is better to cover in a separate post. Let us just make this short and sweet ;)

Download few examples with full source below. And don't forget to post your comments/feedback!
jira-soap-client.zip
File Size: 20 kb
File Type: zip
Download File

 


Comments

u203963
04/13/2011 7:48am

I made the sopaclient according to your tutorial. I was successfull in making it, was able to build the jar file etc. BUT, your java classes in com.jtricks are mostly mainclasses (which are normally directly startable in eclipse). SOAP seems to be a WebService and there the jar file is not startable like java -jar xxxx.jar. HOW DO I RUN for example the login class?? My WSDL points to my local jira instance and i guess all the rest should be ok. I just don't know how to start it up!! Or is that only possible via RPC plugin? IF yes, why the main classes? Thanks

Reply
J-Tricks
04/13/2011 11:54am

I am not sure if I understood the question correctly, but you can just run the main class from your Eclipse itself if you want. The classes do different things as explained in them - Create issue, update it etc etc.

Here we are writing a client and it can be a main class or a web application or anything else. But the concept and the way we call the actual SOAP service is same!

Reply
u203963
04/14/2011 12:30am

Thanks a lot. That was exactly what i wanted to know. It was strange because Eclipse did not offer me the possibility of 'run as java application' and that's why i thought that it must be started somehow different. I will have to try again. Thanks a lot. Mario

Reply
04/29/2011 8:33am

Hi. After consuming lot's of your tutorials, i made a step forward in understanding how jira itself and soap client in special are working. I am able now to read most of the content via soap api BUT, in heavens sake, how do i make getvalue() with remoteFieldValue(). I am able to read all the names and id's of the fields (normal, not customized) from my JIRA Installation but havent find out how to get the values. Lets say i have 10 fields, i have the names and the id's. How do i get the values? I would be infinity thankfull of a little example.
Thanks for the great job you are doing.
Rgds Mario (of of the rain in Switzerland)

Reply
J-Tricks
04/29/2011 9:12am

RemoteIssue has a method getCustomFieldValues which can be used for it.

Check out the printAllCFs class in the attached source code.

Reply
u203963
05/02/2011 1:49am

Thank you. But i have alread learned from your printAllCFs class how to read
CustomFields. What i don't know are how
to read the 'normal' Fields.

It should work with this code:

remoteFieldValue.getValues());

But i don't know how to use it, how to call the constructor for having all the data to read them via ....getValues()

With CutomFieldValues i have
RemoteCustomFieldValue[] cfValues = issue.getCustomFieldValues();

issue.getCustomFieldValues() gives me all i need.

But with remoteFieldValue i have no such methode for class issue.

jiraSoapService.getFieldsForEdit(authToken, ISSUE_KEY); offers me the the remoteField but from there i can read only the id and the name but not the value????

therefore, what i don't know is the
second part of

RemoteFieldValue[] remoteFieldValue = .................; (reading my fields)

Thanks a lot in advance

Reply
J-Tricks
05/02/2011 1:58am

Normal fields are all accessible from RemoteIssue, isn't it?

http://docs.atlassian.com/rpc-jira-plugin/latest/com/atlassian/jira/rpc/soap/beans/RemoteIssue.html

Which normal field are you not able to access? Can you give an example?

Reply
u203963
05/03/2011 12:39am

Sorry, i am stupid!! remoteFieldValue.getValues()) gave me the idea that there must be something else than the getters of RemoteIssue.
Sorry and thanks for all the help.

Reply
06/29/2011 11:54pm

Hi, Is it possible to create Jira Custom Fields remotely from our application using SOAP API?

Reply
J-Tricks
06/30/2011 1:06am

@Kranti,

Unfortunately SOAP doesn't support creation of custom fields. It is not supported in other remote APIs like REST and XML/RPC as well.

Reply
Dixon
08/23/2011 1:21pm

I don't understand how to build this. Is it not possible to have a SOAP GUI app run and remotely connect to Jira? I can run it with ALL the jar's maven imports packaged in my runnable jar, but I don't want a 100 MB jar file. Is there any way around this? Is that the wsdl file?

Reply
J-Tricks
08/23/2011 2:36pm

@Dixon Download the attached source here and run mvn -Pbuildclient. You will get a client jar with dependencies, less than 3MB in size. That is all you need.

Reply
01/25/2012 1:02am

Thank you J-Tricks, you really saved my day. I could able to complete my SOAP client for JIRA in min. until this day I thought it is difficult for a beginner like me.

Reply
Eddie
03/09/2012 9:00am

Hey everyone, how do i get the "authToken" part of "RemoteIssue createdIssue = jiraSoapService.createIssue(authToken, issue);" ?

Thanks in advance!

Reply
J-Tricks
03/09/2012 9:22am

Eddie, You can find it here: http://www.j-tricks.com/1/post/2010/08/jira-soap-client.html

Reply
05/21/2012 1:06am

You gave great points here. Thank you for your great article and I enjoyed reading it keep the good work.I hope can share with you together more wonderful blog,and looking forward to your next article.

Reply
Heat
05/31/2012 1:20am

Hi, some great articles here and sample code to get a beginner started!

I was wondering if you know of a way to get the values of labels? They don't seem to be custom fields, and are displayed in the html like this:-

ul id="labels-518282-value" class="labels">
<li>
<a class="lozenge" title="QASignedOff" href="/jira/secure/IssueNavigator.jspa?reset=true&jqlQuery=labels+%3D+QASignedOff">

Keep up the good work,
Thanks

Reply
J-Tricks
05/31/2012 5:46am

Which version of JIRA is it? Labels used to be custom fields but are now a system field.

Reply
Heat
05/31/2012 5:53am

Sorry I should have included version of Jira is 4.3.3, so I think the labels are now a system field, as they are not being returned as custom fields.

I can't see labels for either Remote Issue or RemoteField, so presuming I would need to use REST for this?

Thanks

Reply
J-Tricks
05/31/2012 8:01am

Unfortunately, yes. REST seems to be the only way! RemoteIssue doesn't expose the labels.

Reply
Aalap
09/26/2012 5:27pm

I am trying to create a issue with a date in past and I tried using setCreated(cal) but it does not seem to set the past date for when the bug was created. Any ideas?

Reply
J-Tricks
09/26/2012 6:18pm

Hi,

JIRA never allows setting time in the past, using remote APIs. It doesn't look at createdDate. It uses the current time instead.

Reply
Achour
08/02/2013 8:48am

try to create issue through SOAP Jira v 4.4.0 ,but I have this error

Executing J-tricks' JIRA SOAP Client
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: Processing instructions are not allowed within SOAP messages
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Processing instructions are not allowed within SOAP messages
at org.apache.axis.encoding.DeserializationContext.startDTD(DeserializationContext.java:1161)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.doctypeDecl(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.doctypeDecl(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.scanDoctypeDecl(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.atlassian.jira.rpc.soap.client.JirasoapserviceV2SoapBindingStub.login(JirasoapserviceV2SoapBindingStub.java:5591)
at org.sonar.plugins.jira.soap.JiraSoapSession.connect(JiraSoapSession.java:58)
at com.jtricks.CreateSimpleIssue.main(CreateSimpleIssue.java:58)

{http://xml.apache.org/axis/}hostname:HRAS09310

org.xml.sax.SAXException: Processing instructions are not allowed within SOAP messages
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:701)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.atlassian.jira.rpc.soap.client.JirasoapserviceV2SoapBindingStub.login(JirasoapserviceV2SoapBindingStub.java:5591)
at org.sonar.plugins.jira.soap.JiraSoapSession.connect(JiraSoapSession.java:58)
at com.jtricks.CreateSimpleIssue.main(CreateSimpleIssue.java:58)
Caused by: org.xml.sax.SAXException: Processing instructions are not allowed within SOAP messages
at org.apache.axis.encoding.DeserializationContext.startDTD(DeserializationContext.java:1161)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.doctypeDecl(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.doctypeDecl(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.scanDoctypeDecl(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at ja

Reply

Your comment will be posted after it is approved.


Leave a Reply


J tricks - Little JIRA Tricks