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.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
input = "{\"username\":\"" + loginUserName + "\", \"password\":\"" + loginPassWord + "\"}";
os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
if (conn.getResponseCode() == 200) {
br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
while ((output = br.readLine()) != null) {
}
conn.disconnect();
}
System.out.println("HTTP " + conn.getResponseCode());
} catch (Exception ex) {
System.out.println("Error in loginToJira: " + ex.getMessage());
}
}
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?
Also:
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:
Cheers,
Dario
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'
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.