Authorization Error 401 occur if calling a Rest Api from Jira Gadget Rest Resource Edited

I am writing a Jira Gadget. For that i have added a rest resource. I have passed oAuth for the currentUser to the gadget and thats working fine when i fetch the projects/issues (using the same oAuth, i have passed to). but when i need to call some tempo rest api's methods in Rest Resource, it throws 401 Authorization error. when i add basic authorization, it works perfect. My problem is that i can not know basic authorization of current user.  My xml for gadget is 

baseUrl: "__ATLASSIAN_BASE_URL__",
useOauth: "/rest/gadget/1.0/currentUser",
view: {


My code in rest resource looks something like below (thats working perfect.)


JqlQueryBuilder jqlBuilder = JqlQueryBuilder.newBuilder();
JqlClauseBuilder clauseBuilder = JqlQueryBuilder.newClauseBuilder();
clauseBuilder = jqlBuilder.where().project(projectid);

final SearchResults results =,clauseBuilder.buildQuery(), PagerFilter.getUnlimitedFilter());


Following is the problemetic area 


String formatedURL = baseURL + "/rest/tempo-planning/1/allocation?startDate=" + StartPlannedDate + "&endDate=" + EndPlannedDate + "&planItemId=" + Long.toString(plan_item_id);

URL url = new URL(formatedURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

//When i un-comment below authorization line; it gives me results, but when i comment below authorization line, it throws 401 error.

//conn.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
conn.setRequestProperty("Accept", "application/json");

if (conn.getResponseCode() != 200) {
log.warn("code forecasted 200");
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
BufferedReader br = new BufferedReader(new InputStreamReader(

String output;

while ((output = br.readLine()) != null) {

//some code here


1 answer

1 vote

Hi! This looks like a developer question, so it would be better to post it at that's where our developer community hangs out :)



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 13, 2019 in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

752 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you