Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

How to POST to a Rest API using Scriptrunner

Hi folks,

I'm trying to post to a rest api using scriptrunner:

import static*
import static*
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")

def http = new HTTPBuilder('https://serviceportal.pornhub.local:443/')
def body = '{"parameters": [ { "value": { "string": { "value": "testu" } }, "type": "string", "name": "username", "scope": "local" }]}'

http.request( POST, JSON ) {req ->
uri.path = 'vco/api/workflows/34c1dc35-1d56-40ec-8741-18fb6ed0d59e/executions/'
body = body

response.success = { resp ->
println "POST response status: ${resp.statusLine}"
assert resp.statusLine.statusCode == 201
catch ( ex) {
log.debug ex.printStackTrace()
log.debug ex.toString()


The call works fine in postman but all i get when i run this through the script console is a with no details as to what I am doing wrong.  Can anyone point out what I am doing wrong?



1 answer

1 accepted

0 votes
Answer accepted

Hi Chris,

First off I'd start with configuring proper handlers for your HttpBuilder. That way you you'll always be able to see what is wrong instead of simply getting an exeption thrown at your face.

I wrote this simple method to create an instance of HttpBuild with all handlers configured:


HTTPBuilder getHttpBuilder(String url) {
HTTPBuilder http = new HTTPBuilder(url)
http.setHeaders(["X-Atlassian-Token": "no-check"])
http.getHandler().failure = { respObject, body ->
[response: respObject, body: body]
http.getHandler().success = { respObject, body ->
[response: respObject, body: body]
return http

Just don't forget to add Authorization header to it.

Now that we have it out of the way I think I found what's wrong with your code. Your request body is a string while is should actually be a JSON. Here's how you fix it:


import groovy.json.JsonOutput

def body = JsonOutput.toJson(["parameters": [ { "value": { "string": { "value": "testu" } }, "type": "string", "name": "username", "scope": "local" }]])

Hope this helps 

Thanks Ivan,

Just what I needed :)

Suggest an answer

Log in or Sign up to answer
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

103 views 0 6
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