It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Rest Client inside Jira plugin

Pedro Felgueiras Community Leader Jun 15, 2016

Hi there, 


I want to get the data from the SLA on my JIRA plugin. 

The way I'm trying to do this is by using the rest service. 

Here is an example of my code: 


String baseUrl = System.getProperty("baseurl");
String resourceUrl = baseUrl + "/rest/servicedesk/1/servicedesk/sla/issue/"+issue.getKey();
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(resourceUrl);
try {
	HttpResponse response = client.execute(request);
} catch (IOException e) {


The output of my code is:

[INFO] [talledLocalContainer] Client must be authenticated to access this resource.



Is there any way to pass the authentication to the HttpClient?  

Is this the better way of getting the sla of an issue? 



1 answer

1 accepted

2 votes
Answer accepted
Petar Petrov Jun 15, 2016

As you've already discovered, calling REST APIs from the server side is not that easy due to the authentication complications - you have several options if you want to stick with that:

  • hardcode credentials and do basic auth (bad idea - hardcoding passwords or even storing them)
  • prompt the user to re-enter the authentication information and do basic auth (you'll need UI for that, bad user experience, as the user is already logged in)
  • get the session cookie from the request and do cookie based authentication - you'll need a way to get the cookie, if you search on answers I think there are some pointers
  • use oauth - never tried it, but configuration seems complicated as it needs to go through application links - search on answers if interested


Since your code is running inside an add-on in JIRA, a much simpler approach for me is to you use the Service Desk java API instead - it looks like it has what you need. Check out the SlaInformationService interface javadoc. You'll need to get hold of the SlaInformationServiceInterface instance, construct a SlaInformationQuery via the builder and call SlaInformationService.getInfo().

Pedro Felgueiras Community Leader Jun 15, 2016

I have gone other way, instead of trying to use the rest api inside JIRA add-on (Java) I have renitente a par of my code to use it on the client side of the api (javascript). 

The Service Desk java API is to much confusing, so I try to avoid it. 

Petar Petrov Jun 16, 2016

Yes, that's a good way to do it as well.

Cesar Cruz Alvarez Jul 17, 2017 • edited

Hi @Pedro Felgueiras,

I need to create a rest client inside Jira plugin too,

I have a question about your last comment:

When you say:  "I have renitente a par of my code to use it on the client side of the api (javascript)"

What do you mean? Could you please provide more info about this? :)

Thank you!!


Pedro Felgueiras Community Leader Jul 18, 2017

The point is that besides quering the api on the java side where you need authentication you can querie it on the client side using the credentials that are loged on jira. 

Cesar Cruz Alvarez Jul 22, 2017

ooh I see, sounds good! :o

Thank you so much @Pedro Felgueiras

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Opsgenie

Introducing Postmortems for Opsgenie

When incidents happen, it is crucial to diagnose and solve the problem as fast as possible. Equally important to this, teams need a way to reflect on why the incident occurred and how they can improv...

216 views 3 6
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you