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

I cant do Post Web Requests(rest api) using Scriptrunner



I'm using the following code


def baseUrl = new URL(‘http://posturl.wtv’)
def connection = baseUrl.openConnection()
def jsonString = ['{"assetstatus": 3,"cinum": "LIS1SBD505","startdatetime": "20210413T16:47:00+00:00","finishdatetime": "20210413T16:49:00+00:00","rootcause": "SSBD.Passageiro.Utilização incorreta","summary": "Scriptrunner Test","ticketca": "TICKET-333333","ticketstatus": "Em Progresso"}']
connection.with {
doOutput = true
requestMethod = "POST"
outputStream.withWriter { writer ->
writer << jsonObj
connection.headerFields.each { println "> ${it}"}


I always get code 200 and if i do a get request i dont get the object asa output.


Can someone help?


Best Regards 


1 answer

0 votes

Scriptrunner comes pre-loaded with some libraries that make doing rest request easier than what you're trying.

You can see their examples here:

I haven't played with the RestClient class myself, I learned to use the HttpBuilder class instead and have stuck with it... here is an example re-using some of your example:



def payload = [
assetstatus: 3,
cinum: "LIS1SBD505",
startdatetime: "20210413T16:47:00+00:00",
finishdatetime: "20210413T16:49:00+00:00",
rootcause: "SSBD.Passageiro.Utilização incorreta",
summary: "Scriptrunner Test",
ticketca: "TICKET-333333",
ticketstatus: "Em Progresso"
def httpBuilder = new HTTPBuilder('your url')
def parsedResponseObject = httpBuilder.request(Method.POST, ContentType.JSON) {
body = payload
headers.authorizationheader = 'base64code'
response.success = {HttpResponseDecorator resp, json -> resp.statusLine.statusCode
resp.headers.each{"$ = $it.value")}
return json
response.failure = {HttpResponseDecorator resp, text ->
log.error "Error: $text"
return [error: text, response:[status:resp.statusLine.statusCode]]

 That might help you get to the bottom of your error.

Suggest an answer

Log in or Sign up to answer

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