Create an option for a single choice customfield via API REST

Patricia González
Contributor
October 6, 2022

Hi,

I want to create an option for a single choice custom field via RES API.

In the documentation it seems it's possible with this: 

Create custom field options (context)

POST /rest/api/3/field/{fieldId}/context/{contextId}/option

But the response i get is:

Invalid request payload. Refer to the REST API documentation and try again.

Here is the code i'm trying:

error_api.png

Thanks!

1 answer

1 vote
robert Mugabuhamye
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 6, 2022

hello @Patricia González  ,

The payload you are providing seems wrong. 
You should provide something like:

 

"options": [ { "disabled": false, "value": "Scranton" }]

 

BODY PARAMETERS

Details of the options to create for a custom field.

options

Array<CustomFieldOptionCreate>

Details of options to create.

CustomFieldOptionCreate → { "value": "<string>", "optionId": "<string>", "disabled": true }

You can see the example here

robert Mugabuhamye
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 6, 2022

and the return code if everything went fine will be http 200, not 204 ;)

Patricia González
Contributor
October 7, 2022

Hi @robert Mugabuhamye,

I tried what you suggested, but it didn`t work either. 

error_api_2.png

(I'm using scriptrunner btw).

Thanks! 

robert Mugabuhamye
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 7, 2022

you should try something like 

 

result = post(url)

.header("Content-Type", application/json)

.body(

     [options:[[disabled:false,value:"scranton"]]]

)

Patricia González
Contributor
October 7, 2022

Hi,

Scriptrunner support provided me with a example code to do this.

It can be found here.

Suggest an answer

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

Atlassian Community Events