Rest Api Groovy Unauthorized


I want to create post function based on REST API but i have problem because with being Unauthorized

This is base code in which i wanted to test connections with rest api

import net.sf.json.JSONArray

def JIRA_URL = "https://myjiraurl"
def JIRA_API_URL = JIRA_URL + "/rest/api/2/"
def jira = new HTTPBuilder(JIRA_API_URL)
jira.auth.basic "login","password"
def test = jira.get(path: 'issue/XXX-5555')

 i get this errors: Unauthorized at at$1.handleResponse( at org.apache.http.impl.client.CloseableHttpClient.execute( at org.apache.http.impl.client.CloseableHttpClient.execute( at at at at$get$ Source) at

I don't know what to do with that :( I think that is because of that my jira instance is on HTTPS not HTTP but i am not sure, can somebody help me?

1 answer

1 accepted

This widget could not be displayed.

This is a quirk of HTTPBuilder. I think your hitting the issue described here.

Following the second example there should help you solve your problem.

Although it looks like your just hitting the issue REST API, you should be able to get all the issue data through the Java API without hitting the REST API.

The following should work for you if you want to do this via the REST API:


def remote = new HTTPBuilder("https://myjiraurl")
def issueJson = remote.request(Method.GET) { req ->
uri.path = "/rest/api/2/issue/XXX-5555"
headers.'Authorization' =
"Basic ${"login:password".bytes.encodeBase64().toString()}"

response.success = { resp, json ->
json ?: [:]

Hello Adam,

Sorry for lat response :( Can you show me example of rest api with script runner? I tried with solutions from your link but it doesn't work (or i dont know how to use it)


I've updated my answer with what should work for you. You'll need to change username and password along with the issue key.

Hope this helps.

Thanks! You are AWESOME!!!! :D

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

146 views 2 0
Join discussion

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