Jira authentication with Java

Alessandro Stella July 9, 2020

Hi, I'm trying to authenticate on my jira server from java with the code below. I got few concerns about the baseURL, not sure how to connect and wich loginUsername and password to use since basic auth is no longer supported. ATM i'm using OAuth credentials created via web gui on JIRA. If trying to use port 8080 i get conn timeout. Using JIRA SERVER not Cloud. Need some help to use REST API pls

public static void main(String[] args) {
String baseURL = "https://alestar.atlassian.net/jira/rest/";
String loginUserName = "user";
String loginPassWord = "password";
URL url = null;
HttpURLConnection conn = null;
String input = "";
OutputStream os = null;
BufferedReader br = null;
String output = null;
try {
url = new URL(baseURL);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "application/json");
input = "{\"username\":\"" + loginUserName + "\", \"password\":\"" + loginPassWord + "\"}";
os = conn.getOutputStream();
if (conn.getResponseCode() == 200) {
br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
while ((output = br.readLine()) != null) {
System.out.println("HTTP " + conn.getResponseCode());
} catch (Exception ex) {
System.out.println("Error in loginToJira: " + ex.getMessage());


1 answer

0 votes
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 17, 2020

Ciao @Alessandro Stella ,

Welcome to the Atlassian Community!

In the attached code snippet I can see the url of a Jira Cloud site: alestar.atlassian.net but then you say you are using Jira Server. Can you kindly confirm which one are you using? 


  • If you are using Cloud then you can just use Basic Authentication with email address and API Token
  • Looking at you code I am not really sure what you are trying to achieve. Can you please clarify?


Finally, please notice that this might not be the best place to get help on development  related questions. In case further help will be needed on this topic, you might want to refer to the resources listed in https://developer.atlassian.com/resources:



Vinod Sashittal
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 25, 2024

Hello Dario and team,

Same code is not working for me either when trying to call below REST API on my JIRA cloud server to login and get the JsessionID. I am using Basic auth with email address and valid API token. Please note I have garbled the sensitive info in below code.

String baseUrl = "https://vxyzabc.atlassian.net/rest/auth/1/session";

String username = "username@gmail.com";
String password = "APItoken";

Response code got from this call = '401'


Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 27, 2024

@Vinod Sashittal  Please notice you are adding your reply to a thread from 4 years ago containing outdated information.

Cookie authentication (calling the session endpoint) has been deprecated in Jira Cloud since 2019 and therefore it is expected not to work: 

You may want to review the current documentation to check the currently supported authentication methods. 


Suggest an answer

Log in or Sign up to answer
Site Admin
AUG Leaders

Atlassian Community Events