Forums

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

ScriptRunner with Curl for REST API call by using Rest endpoint

sgole
Contributor
February 14, 2020

Hi,

I have the following code (in ScriptRunner):

TestGeos111(httpMethod: "POST"){ MultivaluedMap queryParams, String body ->

def curl = "curl \
-u <uname>:<password> \
-X POST\
--data '{"validator": "name","comments": [{"body": "Project has been validated."}],"items": [{"type": "hours","reference": "3HSWDEVELOPMENT","description": "Software engiener hours [Phase: 1.1.5. Layout void any misswork]","quantity": 66,"unitPrice": 500.00},{"type": "hours","reference": "3HSUPPORT","description": "Support Engineer hours [Phase: 8. Validation]","quantity":55,"unitPrice": 200.00}]}' \
-H Content-Type:application/json \
https://ebes.example.com/API/Engineering/Analysis/Validate?Plant=EAES&PartNumber=R170025Y001001"

def output = curl.execute().text

}

but i get below error . Is my way to pass json body is incorrect ? please help me with this .

image.png

 

1 answer

0 votes
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 3, 2020

Hello @sgole ,

I might not be the best person to answer this question since I don't use scriptrunner myself but, reading the returned error message, it looks like the part of text inside the square brackets is not treated as normal text:

[Phase: 1.1.5. Layout void any misswork]

 

Now, even if the below body looks correct, can you kindly try the following:

  1. Confirm everything works fine by running the same command from the terminal (if it fails, please paste the output in here):
    curl \
    -u <uname>:<password> \
    -X POST\
    --data '{"validator": "name","comments": [{"body": "Project has been validated."}],"items": [{"type": "hours","reference": "3HSWDEVELOPMENT","description": "Software engiener hours [Phase: 1.1.5. Layout void any misswork]","quantity": 66,"unitPrice": 500.00},{"type": "hours","reference": "3HSUPPORT","description": "Support Engineer hours [Phase: 8. Validation]","quantity":55,"unitPrice": 200.00}]}' \
    -H Content-Type:application/json \
    https://ebes.example.com/API/Engineering/Analysis/Validate?Plant=EAES&PartNumber=R170025Y001001

     

  2. If everything looks correctly from the terminal, then just try to remove the parts among square brackets in your code, execute it again and see if this is now working or if any other error is returned:
    TestGeos111(httpMethod: "POST"){ MultivaluedMap queryParams, String body ->

    def curl = "curl \
    -u <uname>:<password> \
    -X POST\
    --data '{"validator": "name","comments": [{"body": "Project has been validated."}],"items": [{"type": "hours","reference": "3HSWDEVELOPMENT","description": "Software engineer hours","quantity": 66,"unitPrice": 500.00},{"type": "hours","reference": "3HSUPPORT","description": "Support Engineer hours","quantity":55,"unitPrice": 200.00}]}' \
    -H Content-Type:application/json \
    https://ebes.example.com/API/Engineering/Analysis/Validate?Plant=EAES&PartNumber=R170025Y001001"

    def output = curl.execute().text

    }

 

I hope this helps.

 

Cheers,
Dario

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events