Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

How to Call Internal Jira Rest URL with scriptrunner

We are trying to implement this solution as part of a listener. This example need me to save the user/password, but we want to use the logged in user when making the call to the rest url. So 2 questions:

  1. When i call a internal rest url in a listener, do i need to authenticate the user?
  2. if yes, how do i use the current logged in user details to authenticate?


boolean associateTestsToTestExecution(testExecKey,listOfTestKeys){
def jiraBaseUrl = com.atlassian.jira.component.ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
def endpointUrl = "${jiraBaseUrl}/rest/raven/1.0/api/testexec/${testExecKey}/test"
url = new URL(endpointUrl);
def body_req = [ "add": listOfTestKeys ]

// you should use a specific user for this purpose
username = "admin"
password = "admin"
def authString = "${username}:${password}".bytes.encodeBase64().toString()

URLConnection connection = url.openConnection();
connection.requestMethod = "POST"
connection.doOutput = true
connection.addRequestProperty("Authorization", "Basic ${authString}")
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }

if (connection.getResponseCode() == 200) {
// OK
return true;
} else {
// error
return false;


1 answer

Hi Krishnanand, 

So that others can benefit from the answer we supplied in your support ticket we are also listing it here: 

As you can see from the example, the XRay team is using hardcoded credentials to interact with the REST API.
They are doing this because for security reason Atlassian does not allow you to get the password from the logged user.

Usually, when interacting with other plugins from Jira you don't need to make a REST call, the plugin exposes some Java API what can be used with the @WithPlugin annotation directly inside the script as explained here . 
Unfortunately, I was not able to find any Java API exposed from XRay.

If XRay needs to get notified by this and there is no Java API available, the only way to achieve this is through the REST API.

If the tracking needs to be done on the Jira side, then we can come up with something to track who is clicking the button. 
If the tracking needs to be done on the XRay side, then there is not much you can do.

We would appreciate if you can accept the answer so that others know about this. 



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

116 views 1 2
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