Hello,
I’m writing this post because I’m facing some issues to bind a java application with Jira. I know how many post it exists, I have looked for this and didn’t find something recent. I have only basics in programmation. However I found some infos. For what I know I should use rest api and find dependencies to add to a Pom.xml. Everything is new for me and I’m a little bit lost. Moreover documentation isn’t rich. Could someone help me with his knowledge to solve this problem with me ? ( A little bit of explanation would be appreciated :) ).
Thank you in advance !
Just to clarify - You are trying to authenticate with JIRA using java programming to send / receive REST API calls?
If that is the case, have a look at my sample here:
http://sreenidhi-gsd.com:9191/display/DEVOPS/Java+Program+for+working+with+JIRA
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your answer. One thing I would like to do is to create a new issue. I don't find recent example for this. I have tried your code. However i can't find all the imports. Where do they come from ? I'm still searching, hoping to find something by myself but If you could help me I would appreciate.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For what I understood I should first establish the connection with my lira server, but should I use your method or with BasicHttpAuthenticationHandleror AsynchronousJiraRestClientFactory ? What is the difference here ?
Then I should create a request and upload it with restClient.getIssueClient().createIssue(issueInput, pm).
Finally I can ask the server and get a JSON.file.
I'm right ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Julien,
Looking at your response, my guess is you are not familiar with JSON and REST services.
To give you a short introduction:
JSON is a simple text based data exchange format.
Look here: http://sreenidhi-gsd.com:9191/display/JAVA/JSON to understand and get references to learn more about JSON.
Why JSON?
JIRA uses something called REST WebServices. A Webservices is a piece of software that makes itself available over the internet to transfer data between multiple system (in this example, between JIRA and Java).
you send commands to webservices through a URL and get responses either through XML or JSON.
JSON is simpler than XML and easier to work with.
If you would like to learn about XML, look here: http://sreenidhi-gsd.com:9191/display/JAVA/XML
How to use REST Webservices and JSON?
First you need to identify the available REST webservice calls available for JIRA.
There is an addon in the Atlassian Marketplace called Atlassian REST API Browser. This is a free addon developed and provided by Atlassian. Download and install this addon in JIRA.
Once installed, you will be able to access it in the Administration Section --> System --> REST API Browser.
Here you can see a list of all available calls for JIRA.
Each call supports one or more methods. (GET, PUT, POST, ..) These methods identify what type of parameters are accepted by the call. TO keep it simple for you, lets just say you can pass parameters through the URL. Once the connection is established, you can perform additional actions using JSON.
Each connection or action returns a response with a code.
Succesful responses are either 200 and 204.
Any failures result in a number greater than 400.
The responses may also JSON results which can be used for further activities.
You can also play with the REST API browser to see how webservices function in JIRA.
NOTE: Any actions made with the REST API browser will have an impact on JIRA. So, use your test / stage / non-prod environment.
Now, getting back to the code I showed you earlier: http://sreenidhi-gsd.com:9191/display/DEVOPS/Java+Program+for+working+with+JIRA
This is written based on the above explanation.
There is no need of any additional modules like BasicHttpAuthenticationHandleror of AsynchronousJiraRestClientFactory .
The code handles the authentication , connection to JIRA, sending REST calls and receiving response all by itself. It is (hopefully) easy to understand.
What it does is create a REST call to JIRAand get information about a particular JIRA issue.
You may have to update the JIRA URL , credentials and the the issue key.
If the connection is successful, it should print the JSON response which JIRA returns.
You should be able to extend the same code to perform other activities like creating issues or modifying them based on the information from the API browser. If you would like help with specific calls, let me know.
Sorry for the long answer, but hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ! Really thank you for this answer I have to understand what you've just said (indeed I'm not familiar with this). I'll comme back to you soon.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In your code, what object is mF ? (URL jiraURL = new URL(JIRA_URL + "/rest/api/2/issue/" + mF.getJIRAID());) .
From which package comes Constants ? (Reader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), Constants.UTF_8_ENCODING));)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In your code you use an URL like "https://jira-url.com". However In my company URL look like : https://asc.mycompany.net/jira/browse/issuename. Is it a problem ? I don't have the rest api browser yet, I'll download it. Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Some answers to your questions:
1. mF.getJIRAID() - this is just a placeholder for the jira issue number.
You can replace with the following:
String JIRA_ISSUE = "JIRA-123" ; //JIRA-123 is the issue number
(URL jiraURL = new URL(JIRA_URL + "/rest/api/2/issue/" + JIRA_ISSUE );) .
2. Constants is a class I have written to store constant variables. You can use:
(Reader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));)
Replace the url with your JIRA base URL:
https://asc.mycompany.net/jira
You can verify and retrieve the JIRA Base URL from Administration --> System --> General Configurations --> Base URL
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
Thank you for your answer. Here is something I don't understand. Three more questions for you, but It helps me a lot, thanks !
We don't use rest api as a .jar ?
You don't even use the rest api in your code ?
Why the URL is (URL jiraURL = new URL(JIRA_URL + "/rest/api/2/issue/" + JIRA_ISSUE );) ? Should the URL not be URL jiraURL = new URL(JIRA_URL + JIRA_ISSUE ) ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
I worked a little bit on it this week-end, and I get a result. It is a huge String containing what I´m looking for. Does it exist a way to extract only a key or an asignee ? Or I should write it by my own ?
I would like now to create a cloned issue. My question is : can I directly use this feature from jira or should I do it manually ?
Thank you in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The REST API functionality is already built into JIRA
Java comes with the capability to perform WebService actions - so you dont need additional jars (unless you are looking for something specific built).
The REST API URL is dynamically generated. If you look at the API documentation mentioned earlier (REST API browser), you can see how the URLs should be constructed.
URL jiraURL = new URL(JIRA_URL + "/rest/api/2/issue/" + JIRA_ISSUE ); does just that.
As mentioned above, the response of the REST Call will be a JSON string. You will need to use (either write your own or use existing) JSON utilities to extract content from the JSON string. Please look at my examples of working with JSON and Java.
http://sreenidhi-gsd.com:9191/pages/viewpage.action?pageId=3997729
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello
Thank you for your answer. Ok thank you for these explanation. But when I searched on Internet last week I found this : https://www.nitendragautam.com/programming/atlassian-jira-rest-client-library/ . What the difference between the two methods ? I would like now to create a cloned issue. Can I directly use this feature from jira or should I do it manually ?
Thank you in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.