ScriptRunner - How to form a get request inside Jira ScriptRunner

 

Hi Community,

I have been looking for ways to construct a get request inside Jira.

I want to use the rest API inside a Behavior to fetch certain board related data: 

<jira Base URL>/rest/agile/1.0/board/{board Id}/configuration

Would anyone know how I can form a get request inside Jira as to receive a response from the url mentioned.

I have tried using the examples in the article but I have been getting this error: 

groovyx.net.http.HttpResponseException: Unauthorized

 I am doing the following in my code:

import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient

def boardId = '3';
def activitiRestClient = new RESTClient("<Jira Base URL>/rest/agile/1.0/board/")
activitiRestClient.auth.basic "USERNAME", "PASWORD"

def response = activitiRestClient.get(
path: boardId+'/configuration'
)

output+="\nresponse: "+response+"\n"

Could someone provide some pointers as to why this isn't working for me?

Thank you!!

-Roberto

1 answer

1 votes

Hello Roberto.

If you look further down the article, you will see that the user was wrong on his first approach, and later on, was able to work it out with this:

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper

def http = new HTTPBuilder('http://IP/authentication')
http.request(POST) {
    requestContentType = ContentType.JSON
    body =  [username: 'USERNAME', password: 'PASSWORD']

        response.success = { resp, JSON ->

  return JSON
            
    }
    
        response.failure = { resp ->
        return "Request failed with status ${resp.status}"
            
        

Could you give that a try and letme know if it works?

Cheers

DYelamos

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

270 views 0 12
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot