Value isn't sent in REST call using ScriptRunner

Mikey Schott June 2, 2020

If I run the following code in ScriptRunner's script console, I get an error back from the response that says I didn't set the value for the 'value' field.

def result = put("/rest/api/3/customField/12345/option")
.header('Accept', 'application/json')
.header('Content-Type', 'application/json')
.body([
options:[
[
value: 'A_VALUE'
]
]
])
.asString()

if (result.status == 201) {
return "Success"
} else {
return "${result.status}: ${result.body}"
}

The error that I get is:

400: {"errorMessages":["Every option is required to have a non empty field 'value'."],"errors":{}}

It seems to me like the value field is NOT empty.

Note that I can run the request in Postman without any errors.

1 answer

0 votes
Casey Moore July 8, 2020

Hi Mikey,

Not Sure if you got this resolved or not, but I'm posting for those like me who Google upon this post. 

The issue as I can tell is that the "options" parent is looking for both "newValue" and "value" even if not updating the parent value.

 

{
"options": [
{
"newValue": "ParentName",
"value": "ParentName",
"cascadingOptions": [
{
"newValue": "NewChildValue",
"value": "OldChildValue"
}
]
}
]
}

 Which is not how I would interpret the documentation.JiraCapture.PNG

Mikey Schott July 8, 2020

Hi, Casey. Thanks for posting. I never resolved this using ScriptRunner, so I just moved forward using Postman and an API token. The body of the request looked like this:

{
"options": [
{"value" : "Alpha"},
{"value" : "Bravo"},
{"value" : "Charlie"}
]
}

 Note that it looks like our use cases might have been different as it looks like you were changing values and I was creating new options values.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events