Jira Cloud REST API (Python) - How to set value for a cascaded select field

Amir Katz (Outseer)
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.
March 26, 2023

Following some posts I've seen, I am using the Python REST API to create a new issue and passing this as part of the dict of the fields:

'customfield_11585': {       # 'my_field' - a cascaded selection field
'value': 'fu', # parent value: 'fu' (id=26637)
'child': {
'id': '26792' # child value: 'bar' (id=26792)
}
},

This results in error 400: "Specify a valid child option 'id' for my_field".

Next I tried to use 'name' instead of 'id' and I get a different 400 error:

"Specify a valid child option 'id' or 'name' for my_field".

Next I tried to use 'value', and I get this error:

"Specify a valid child option 'name' for my_field".

I also tried to use the option name ('bar') instead of the id, but to no avail.

The only thing that does succeed is when I pass an empty child, like this:

'customfield_11585': { 
'value': 'fu',
'child': None
},

So I know that the REST API call to set the field with the parent works, but I can't set the child option.

The documentation does not provide an example of setting a cascaded field:

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post

3 answers

1 accepted

1 vote
Answer accepted
David Freitez
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.
March 26, 2023

Hi @Amir Katz (Outseer),

I think your JSON is not working properly, I made a test with automation and the Advanced editing option, which uses a Json, and I managed to update the value of the cascading field.

Here is the JSON I  used: the options values and worked:

{
"fields": {
"Cascading field" : { "value": "Parent 1", "child": { "value" : "Child 1 - 2"} }
}
}

I also used ID of the child option and worked:

{
"fields": {
"Cascading field" : { "value": "Parent 1", "child": { "id" : "10160"} }
}
}

image.pngimage.pngimage.png

 

In the last image, note that I got the value from the child issue from the URL: https://xyz.atlassian.net/secure/admin/EditCustomFieldOptions!edit.jspa?fieldConfigId=10215&atl_token=0252bc82-60e3-437a-b636-f571e158a51c_f294694fe493a2305a69c4a347a3e4019a69def7_lin&selectedParentOptionId=10157&selectedValue=10160

If I test with a wrong ID, like 101600, it would give the error you are getting:

image.png

 

Can you check the IDs you are using and also the JSON you are using with the one that worked for me?

I hope this helps you clarify your inquiry.

Regards,
David

David Freitez
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.
March 26, 2023

Oh... I forgot to say, I know your request has to do with Python, but in this case, I think the problem is regarding the JSON.  Please try to double check the JSON and the options (parent and child) ids and hopefully the problem is solved.

Regards,
David

0 votes
Easy for Jira January 22, 2024

Hi guys,

If you like to use python with Jira, I would like to invite you to use Easy for Jira. The app was launched on December 2023.

It's a Python extension for Jira cloud.

This is the marketplace listing link
And this is the community post where I announced it

Thank you!

Best,

Easy for Jira

0 votes
Amir Katz (Outseer)
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.
March 26, 2023

Thank you David. I tried the same code with a different cascading field and it worked.

At that point I realized that the problem was not the JSON, but the values - the values that I have specified for the "problematic" field were not aligned with the context of the field - the values I was specifying are in context A, but the project+issue type I was trying to create the issue in are in context B, which had a different set of parents and children.

Life lesson: when setting a selection field via the Jira REST API, make sure that the value (or pair of values for a cascading field) is in the context of the project and/or issue type.

David Freitez
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.
March 27, 2023

Hi @Amir Katz (Outseer)

Good catch, I am glad you were able to solve it !! :-)

Have a great start of the week,
David

Like Amir Katz (Outseer) likes this

Suggest an answer

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

Atlassian Community Events