The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue calling REST Endpoint from ScriptRunner Using HTTPBuilder

Terry Robison
Contributor
April 7, 2022

I am calling a REST Endpoint utilizing HTTPBuilder. I thought I had a pretty solid example from this post.

I can successfully call the REST Endpoint from Postman with Basic authentication.

However, I am getting a couple of errors in the script console. 

The request object should be resolved from the http object is my understanding, but no addHeaders() method appears in the code completion.

ContentType.png

 

request.png

 

completion.png

CODE


import
groovyx.net.http.HTTPBuilder

import static groovyx.net.http.ContentType.*

import groovyx.net.http.ContentType

import static groovyx.net.http.Method.*




def http = new HTTPBuilder('https://<host>/rest/scriptrunner/latest/custom/getLicenseStat')

http.headers = [Accept: 'application/json', charset: 'UTF-8']

def authString = "<acct>:<pass>".getBytes().encodeBase64().toString();




http.request(POST, ContentType.JSON) {

    requestContentType = ContentType.JSON

    request.addHeader("authorization: Basic ${authString}", "ContentType: application/json")

    body =  [user: '<username>']




    response.success = { resp, JSON ->

        return JSON

    }

}

 

0 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events