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

0 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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jun 14, 2018 in Jira Service Desk

How the Telegram Integration for Jira helps Sergey's team take their support efficiency to the bank

...+ reading Fantasy). The same is true for him at the bank he works for: Efficiency is key when time literally equals money. Read on to learn how Sergey makes most of the time he has by...

503 views 3 5
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