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

Jira authentification in 2018

Julien October 22, 2018 edited

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 !

1 answer

1 accepted

0 votes
Answer accepted
Gundlupet Sreenidhi
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.
October 22, 2018

Just to clarify - You are trying to authenticate with JIRA using java programming to send / receive REST API calls?

Gundlupet Sreenidhi
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.
October 22, 2018
Julien October 24, 2018

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.

Julien October 24, 2018

I definitly don't find correct imports. Could you please give me a link for these mbfs and json ? Thank you.

Julien October 24, 2018

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 ? 

Gundlupet Sreenidhi
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.
October 24, 2018

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. 

image.png

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. 

image.png

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.

Julien October 24, 2018

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. 

Julien October 24, 2018

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));)

Julien October 24, 2018

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

Gundlupet Sreenidhi
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.
October 25, 2018

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

image.png

Julien October 26, 2018

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 ) ? 

Julien October 29, 2018

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

Gundlupet Sreenidhi
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.
October 29, 2018

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

Julien October 30, 2018

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

Julien November 6, 2018

Hello,

 

I think it's no more a correct subject here. I close it, thank you for your help.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

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
AUG Leaders

Upcoming Jira Events