Please, allow creating issues in JRJC. REST API already has this capability.
If it is possible, let me know how it is done. I didn't get it.
thank you
Community moderators have prevented the ability to post new answers.
Try using Jersey. There are some examples here: http://www.j-tricks.com/1/post/2012/05/java-rest-client-for-jira-using-jersey.html
I have seen that one. I'd prefer if Atlassian improved the JRJC instead
Cheers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The newly released JRJC API supports adding a new issue, this is how I did it and hope it will help somebody else.
//populate issue fields
com.atlassian.jira.rest.client.domain.input.IssueInputBuilder issueBuilder = new IssueInputBuilder("ProjectKey", "IssueType");
issueBuilder.setDescription("issue description");
issueBuilder.setSummary("issue summary");
//create the client
BasicHttpAuthenticationHandler myAuthenticationHandler = new BasicHttpAuthenticationHandler("jira.username", "jira.password");
JerseyJiraRestClientFactory factory = new JerseyJiraRestClientFactory();
URI jiraServerUri = new URI("http//jira.yourdomain.com");
JiraRestClient restClient = factory.create(jiraServerUri, myAuthenticationHandler);
//create the issue
NullProgressMonitor pm = new NullProgressMonitor();
com.atlassian.jira.rest.client.domain.input.IssueInput issueInput = issueBuilder.build();
BasicIssue bIssue = restClient.getIssueClient().createIssue(issueInput, pm);
//get the newly created issue
com.atlassian.jira.rest.client.domain.Issue jIssue = restClient.getIssueClient().getIssue(bIssue.getKey(), pm);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In which version of JIRA does creating an issue this way work for you? I get the below error with JIRA 4.4.3
com.atlassian.jira.rest.client.RestClientException: com.sun.jersey.api.client.UniformInterfaceException: Client response status: 405
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I am using JIRA 5.2, but according to the 'release notes' for JRJC v1.0 this functionality on JIRA v4.2 - 5.1.8. is supported. As a trouble-shooting question: are you able to retrieve an existing issue when using the 'JiraRestClient' object without getting this exception? E.g. com.atlassian.jira.rest.client.domain.Issue jIssue = restClient.getIssueClient().getIssue("Existing issue key", pm);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I can get an existing issue using the JiraRestClient without any exception. I can get a project's details as well. Only the issue creation throws exception. I saw the supported versions too, but not sure if all features are supported across all versions.
I tried adding a comment to an existing issue and got the same exception.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Am afraid I cant help any further since in my case it worked for both 'comment' and 'issue', I would assume you have tried 'curl' and 'Jersey Client' with success. If that is the case then we can assume its a bug within the JRJC that affects your JIRA version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, thanks for your help. I had no luck creating issue using the REST API with Jersey Client.. but the wiki clearly states that this is available only from JIRA version 5. (mine is 4.4.3)
I will post my question to the forum and see.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi am using Jira 5.2 and apart from the fields you have mentioned, mandatory fields include 1.Steps to reproduce, 2) Detection and discipline and 3) Defect severity. How to set these values when creating a new issue from JRJC
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
//If its a multi-select field on jira
issueBuilder.setFieldValue("customfield_1234", ComplexIssueInputFieldValue.with("value", "selected value"));
//If its a not a multi-select field, normal field
issueBuilder.setFieldValue("customfield_1234", "your value");
Note: 'customfield_1234' is the ID of the field name in Jira e.g. 'Steps to reproduce' might have and id of '1234'
I prefer that since the name of the field can be changed whereas the ID hardly changes unless u delete that field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@sabza, ya i agree. It throws 400(Bad request) when username/password given wrong when connecting via JRJC and i can able to get the actual cause from the exception. My question is, when wrong uname/password given twice/thrice to connect JIRA via JRJC , then i cant connect to JIRA again from JRJC unless i login using GUI by giving captcha. Is there any alternative approach to deal this case programatically rather than using GUI of jira for login.??
Thanks,
sre
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The is no other way you can deal with that in JRJC since the purpose of CAPTCHA is to prevent unwanted internet bots from accessing JIRA thereby causing catastrophe. If you dont want CAPTCHA you can disable it, for more information have a look at: https://confluence.atlassian.com/display/JIRA/Enabling+Public+Signup+and+CAPTCHA. I hope this brought some clarity to your question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@sabza as mentioned by you in your earlier post, for multiselect value issueBuilder.setFieldValue("id of the custom filed",ComplexIssueInputFieldValue.with(String key,object value)
if my values were A,B,C in multiselect and if i need to select A in the list my value will be "A" and what about the key ??
id of the custom field = customfiled_1234 (for ex)
value= "A"
key ? . Thanks in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My example looked like this: issueBuilder.setFieldValue("customfield_1234", ComplexIssueInputFieldValue.with("value", "selected value"));
So in your case it would be something like:issueBuilder.setFieldValue("customfield_1234", ComplexIssueInputFieldValue.with("value", "A"));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@sabza I solved that issue and now it is working fine. I have a quick question . If username/password given wrong twice/thrice in JIRA GUI it asks for captcha. But when connecting via JRJC if i intentionally give wrong username/password it throws UniformInterfaceException. If i again hardcode it to correct password/username, it throws the same exception unless i login via GUI and give captcha. How to solve this programatically ? is there any possible way to handle it ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Am not sure what your really question is, but will respond based on UniformInterfaceException. Any request (e.g POST, GET, DELETE) to JIRA that does not result to a response with a status of say 200 (OK), meaning the request was not successful would be handled by UniformInterfaceException. Meaning whether you supplied a wrong password or sent a wrong query to JIRA it would be handled by UniformInterfaceException. Then you can dig deeper on the exceptions to get the actual cause.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ya i have included both 'jersey-client-1.5.jar' and 'jersey-apache-client-1.5.jar' .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your problem still lies on the 'jersey-apache-client-?.jar' you can try to replace your 1.5 version with a newer version, say 1.10/11/... I have tested with that (1.10) and I don't have issues.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting the below exception while executing the create issue code. My jira is running in http://localhost:8080 . I hope i have included all the dependencies mentioned. am using Netbeans 7.3 IDE.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/auth/AuthScope at com.sun.jersey.client.apache.config.ApacheHttpClientState.setCredentials(ApacheHttpClientState.java:121) at com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler.configure(BasicHttpAuthenticationHandler.java:42) at com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClient.<init>(JerseyJiraRestClient.java:65) at com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory.create(JerseyJiraRestClientFactory.java:34) at my.jira.jira.main(jira.java:43) Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.auth.AuthScope at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 5 more Java Result: 1
Expecting your reply for this post and for the earlier one. thanks in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check if the 'jersey-apache-client-v?.jar' is included, am currently using 'jersey-apache-client-1.10.jar' You also need to include 'jersey-client-v?.jar' am using 'jersey-client-1.5.jar'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@sabza Thanks . yes you are right. while passing (String,Long) where project key is of type string and how yo get the value of issuetype to denote it as Long. In the form it is like Bug,new feature as i mentioned earlier. If i want to denote the issue type as "Bug" what i need to do. sorry if it is silly question i want to clear the basic out of this.
will JRJC 1.0 supports JIRA 5.2.11 ? but when i go through the pom.xml i found version 5.1. But in your earlier post you mentioned you worked out the create issue in version 5.2.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To get the ID of the IssueType check my response to your question on this date ' Apr 23 at 09:01 AM' Instead of choosing 'Fields' choose 'IssueType' then on the issue type select the 'Edit' then you will see the ID on the URL. Alternatively you can get it through code:
Iterable<com.atlassian.jira.rest.client.domain.IssueType> allIssueTypes = restClient.getMetadataClient().getIssueTypes(pm); for (com.atlassian.jira.rest.client.domain.IssueType jIssueType : allIssueTypes) {
if( jIssueType.getName().equals("Bug"){ Long issueTypeID = jIssueType.getId(); String issueTypeName = jIssueType.getName(); String issueTypeDescription = jIssueType.getDescription(); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
com.atlassian.jira.rest.client.domain.input.IssueInputBuilder issueBuilder = new IssueInputBuilder("ProjectKey", "IssueType");
it didn't accept (String,String) . It asks for (String,Long). But the template in JIRA is like project and issuetype like (Bug,new feature,etc) . then what will be the value of those issuetype . if so how to find it. Pls help on this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, 'IssueInputBuilder' object does not support (String, String) constructor, pass the project key as string type and the issue type id as Long type. Alternatively you can create a BasicIssueType object and BasicProject object and pass them as parameters of the 'IssueInputBuilder' object. e.g. IssueInputBuilder iib = new IssueInputBuilder("CCZA", 1L)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@sabza Okay thanks :) 'll try it . may i know how to find the id of a particular field? eg the fields i mentioned earlier. and i more quick question, should i need to make remote API connection on in jira to access jira using JRJC programatically.. Thanks in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Log-in to Jira with administrative permissions, then go to 'Administration' on the top-right corner. Then go 'Issues-->Fields' a list of custom fields would be displayed then choose the one you want find its ID, then click 'Configure' on the gear image. Once that is done you can check the URL, the last number on the URL is the ID of the field. The URL will look something like: http://jira.atlassian.com/secure/admin/ConfigureCustomField!default.jspa?customFieldId=10500.
To answer your question about connecting, look on the lines below '//create the client' on the response above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you include the jar 'json-lib-2.4-jdk15.jar' available at http://sourceforge.net/projects/json-lib/files/latest/download?source=files
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I am getting the below exception while using the above code.
Feb03,20132:15:25 PM com.sun.jersey.api.client.RequestWriter$RequestEntityWriterImpl<init> SEVERE: A message body writer forJavaclass org.codehaus.jettison.json.JSONObject, and Java type class org.codehaus.jettison.json.JSONObject, and MIME media type application/octet-stream was not found Feb03,20132:15:25 PM com.sun.jersey.api.client.RequestWriter$RequestEntityWriterImpl<init> SEVERE:The registered message body writers compatible with the MIME media type are: application/octet-stream ->
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you include the jar 'json-lib-2.4-jdk15.jar' available at http://sourceforge.net/projects/json-lib/files/latest/download?source=files |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I too had this issue. I have added json-lib-2.4-jdk15.jar in the build path. Still the exception is throwing from the same code segment. "final Issue issue = restClient.getIssueClient().getIssue("RAD-1", pm);"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
According to the 'release notes' for JRJC v1.0 this functionality on JIRA v4.2 - 5.1.8. is supported. Check:https://marketplace.atlassian.com/plugins/com.atlassian.jira.jira-rest-java-client;jsessionid=1eu5ccv8t8lam1mbazqli3wpb9
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.