Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hello,
I'm trying to add options to a customfield using this script:
// The issue key
def issueKey = issue.key // or you can try with a real issuekey "PAA-679"
// Obtenir le ticket à partir de la clé de celui-ci
def ticket = get("/rest/api/2/issue/${issueKey}")
.header("Content-Type", "application/json")
.asObject(Map)
.body
// Obtenir tous les champs
def fields = ticket.fields as Map
final issueSummary = fields.summary
final CodeProjet = issueKey.replace("-",".")
final Projet = (CodeProjet + " " + issueSummary).toString()
def Creation = true
// Obtenir les valeurs existantes
def valeurs = (get("/rest/api/3/field/customfield_10546/context/10810/option")
.header("Content-Type", "application/json")
.asObject(Map)
.body)
for(value in valeurs.values)
{
if (valeurs.value == Projet)
{
Creation = false
}
}
if ( Creation == true )
{
def payload = [
options: [
disabled: false,
value: Projet
]
]
print payload
post("/rest/api/3/field/customfield_10546/context/10810/option")
.header("Content-Type", "application/json")
.body(payload)
.asString()
}
but I keep getting this error, can you please help me? :)
POST request to /rest/api/3/field/customfield_10546/context/10810/option returned an error code: status: 400 - Bad Request
body: {"errorMessages":["Invalid request payload. Refer to the REST API documentation and try again."]}
I tried several things, replacing the variable value with “test”, putting .asObject(Map) instead of .asString() put the post action in this format:
post("/rest/api/3/field/customfield_10546/context/10810/option")
.header('Content-Type', 'application/json')
.body([
options: [
disabled : false,
value : Projet
]
]).asString()
Hi @ALARY Yann, the payload is a list of new options, like:
def payload = [
options: [
[
value: 'newOptionA',
],
[
value: 'newOptionB',
],
]
]
You also do not actually need `disabled: false,`.
So, even you are just adding one new option, you still need brackets to enclose the new option:
def payload = [
options: [
[
disabled: false,
value: Projet,
]
]
]
Hope this helps.
Hi @Max Lim _Adaptavist_ ,
It works, thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.