Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events