Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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

0 votes

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

Atlassian Community Events