Getting Authentication error while using Rest API for Atlassian Cloud sites

gaurav_pandey July 3, 2019

We are using the below code to apply filters and fetch list of Jira id's in version 1.0 - 

 

URI jiraServerUri = null;
JiraRestClient client = null;
StringBuilder resultString = new StringBuilder();

try{
log.info("Executing JQL Query = "+jqlquery);
jiraServerUri = new URI(jiraUrl);
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
client = factory.createWithBasicHttpAuthentication(jiraServerUri, username, password);
SearchRestClient searchClient = client.getSearchClient();
SearchResult result = searchClient.searchJql(jqlquery).claim();

for(Issue issue : result.getIssues()){
String JiraStatus = issue.getStatus().toString().split("name=")[1].split(", id")[0];
String JiraTitle = issue.getSummary().toString();
resultString.append(issue.getKey()+"&nbsp&nbsp - &nbsp&nbsp"+JiraTitle+"&nbsp&nbsp - &nbsp&nbsp"+JiraStatus+"<br>&nbsp&nbsp");
}

 

+++++++++++++++++++++++++++++++++++++++

Now , after upgrading Jira , we are getting below exception at SearchResult result = searchClient.searchJql(jqlquery).claim();- 

 ]RestClientException{statusCode=Optional.of(401), errorCollections=[]}
	at com.atlassian.jira.rest.client.internal.async.DelegatingPromise.claim(DelegatingPromise.java:47)
	at com.utility.Jira.executeJQLQuery(Jira.java:46)
	at com.impl.Querying.coreLogicToRunSuite(Querying.java:640)
	at com.impl.Querying.clearBlockCache(Querying.java:425)
	at com.impl.Querying.executeSuiteBasedOnUserDefinedOperation(Querying.java:220)
	at com.impl.Querying.operationBeforeExecutingSuite(Querying.java:195)
	at com.impl.Querying.readEnviromentDetailsAndAssign(Querying.java:178)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
	at org.testng.TestRunner.privateRun(TestRunner.java:767)
	at org.testng.TestRunner.run(TestRunner.java:617)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
	at org.testng.SuiteRunner.run(SuiteRunner.java:240)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
	at org.testng.TestNG.run(TestNG.java:1031)
	at com.impl.MainClass.main(MainClass.java:329)
Caused by: RestClientException{statusCode=Optional.of(401), errorCollections=[]}
	at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:175)
	at com.atlassian.jira.rest.client.internal.async.AbstractAsynchronousRestClient$2.apply(AbstractAsynchronousRestClient.java:167)

 

We are not able to find any document as in what changes are required (in code or jars/dependencies) to make it work.

 

Any help would be very much appreciated.

2 answers

0 votes
gaurav_pandey July 3, 2019

 Jira Cloud (aka Jira OD) has ongoing deprecation of basic authentication. What you need to do is create an API token and use it instead. The API itself didn't change. I believe this is why you started getting 401 status codes.

0 votes
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 3, 2019

Hello @gaurav_pandey,

The code you posted doesn't look like it is requesting Bitbucket Cloud – it connects to Jira and executes some JQL (Jira Query Language), so it has nothing to do with Bitbucket Cloud v1.0 API deprecation.

The error you get though likely means that the request is unauthorized (HTTP code 401) – so something is rather wrong with the credentials you passed in.

Hope this helps.

Cheers,
Daniil

gaurav_pandey July 3, 2019

@Daniil Penkin  - Thanks for the quick response.

The credentials we are using are hard-coded and they are being used from long time and suddenly stopped working.

We did not made any changes in the code or credentials. We checked the credentials ad well as the JQL query manually and its working just fine.

The only change is we have updated Jira to 3.3.0-OD after which it stopped working.

We are not sure what is the root cause of this problem and found multiple blogs with the same issue which are unanswered.

 In release notes we found out that few API's are deprecated which lead us to believe that this is the root cause.

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 3, 2019

No worries @gaurav_pandey, I'm happy to help.

Bitbucket API deprecation that you referred to in the title of this question is not related to Jira Cloud. Bitbucket Cloud is a separate product which your script is not interacting with.

However I just found that Jira Cloud (aka Jira OD) has ongoing deprecation of basic authentication. What you need to do is create an API token and use it instead. The API itself didn't change. I believe this is why you started getting 401 status codes.

Let me know if this helped.

Cheers,
Daniil

gaurav_pandey July 3, 2019

@Daniil Penkin - Thanks for your help. It worked !!!

Really appreciate your timely replies.

Like Daniil Penkin likes this

Suggest an answer

Log in or Sign up to answer