Create
cancel
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

Scriptrunner pulling back External API

@grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON


try{
def rest = new RESTClient('https://status.cernerops.com')
String token = '<bearer token>'
def response = rest.get(
path: '/api/incidents?q=jira2&unresolved=',
headers: [Authorization: "Bearer ${token}"],
requestContentType: JSON )

response.responseData

} catch(Exception ex) {

log.warn "Error: ${ex.message}"

}

 

Keep getting a 401 like the authorization is not passed.  Works in postman but not from my script.

1 answer

Hi @Kevin Dalton ,

Do you see the same 401 response error using our library script? If yes, could you please test with curl command in the JIRA server instance and verify if its still hitting the same problem?

We were able to figure it out.  Stupid Headers ;)

http.request(GET, JSON) { req ->
uri.path = csdincident+svcSearch
headers.'Authorization' = "Bearer $access_token"
headers.'Content-Type' = 'application/json'
headers.'User-Agent' = 'Mozilla/5.0'

}

Like John Chin likes this

Short and sweet.  We call the API of our incident management applications.


if (tool.toString().contains('JIRA1')) {
def svcSearch = '?service_id=' + JIRA1 + '&unresolved=true'
def GETsearch = ( http.request(GET, JSON) { req ->
uri.path = csdincident+svcSearch
headers.'Authorization' = "Bearer $access_token"
headers.'Content-Type' = 'application/json'
headers.'User-Agent' = 'Mozilla/5.0'

}).toString()
if (GETsearch.size() > 2){
String[] variables = GETsearch .split(",");
String name = variables[1];
def namefix = name.replaceAll("name:","")
String contract = variables[3];
def contractfix = contract.replaceAll("contracts:/api/incidents/","https://status.cernerops.com/incidents/").replaceAll("/contracts]]","").replaceAll("/contracts]","")
HELP = HELP + '<a href="' + contractfix + '">' + namefix + '</a><br><br>'
}}


Then we do some parsing of the JSON to build a nice big red box informing our users on create that there is an incident.


if (HELP.toString()){
HELP = HELP.substring(0, HELP.length() - 8)
ArtInstField.setHelpText('<p style="border:3px; border-style:solid; border-color:#FF0000; padding: 1em;">There is a known incident/s logged to CSD please refer to the following.<br><br>'+ HELP + '</p>')
}
else {
ArtInstField.clearHelpText()
}

 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

Security Advisory for Jira Service Management

On October 20, 2021, Atlassian published a security advisory for Jira Service Management. The full advisory is available at this link.  We've seen a number of questions already asking for...

72 views 0 1
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