Jira Cloud fields and work types
Jira cascading select custom field: parent and child via API
The cascading select takes {"value": parent, "child": {"value": child}} and reads back as an option with a nested child. The child may be left out; a child that does not belong to the chosen parent is a 400.
Endpoints
| Method | Path | What it does |
|---|---|---|
PUT | /rest/api/3/issue/{issueIdOrKey} | Sets or changes the value. |
GET | /rest/api/3/issue/{issueIdOrKey} | Reads the stored value. |
POST | /rest/api/3/search/jql | Finds work items by value. |
GET | /rest/api/3/field/{fieldId}/context/{contextId}/option | Lists the options. |
GET | /rest/api/3/issue/{issueIdOrKey}/editmeta | Lists what can be edited. |
Examples
PUT /rest/api/3/issue/{issueIdOrKey}
Sets Europe with the child Romania.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"customfield_10168": {
"value": "Europe",
"child": {
"value": "Romania"
}
}
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10168'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.put(
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10168',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'customfield_10168'},
json={'fields': {'customfield_10168': {'value': 'Europe', 'child': {'value': 'Romania'}}}},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-6",
"fields": {
"customfield_10168": {
"self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10047",
"value": "Europe",
"id": "10047",
"child": {
"self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10049",
"value": "Romania",
"id": "10049"
}
}
}
}Sent to Atlassian Cloud on .
PUT /rest/api/3/issue/{issueIdOrKey}
Leaving the child out is accepted and the response has no child.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"customfield_10168": {
"value": "Europe"
}
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10168'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.put(
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10168',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'customfield_10168'},
json={'fields': {'customfield_10168': {'value': 'Europe'}}},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-6",
"fields": {
"customfield_10168": {
"self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10047",
"value": "Europe",
"id": "10047"
}
}
}Sent to Atlassian Cloud on .
PUT /rest/api/3/issue/{issueIdOrKey}
Asia with Romania as child is refused, because Romania sits under Europe.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"customfield_10168": {
"value": "Asia",
"child": {
"value": "Romania"
}
}
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10168'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.put(
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10168',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'customfield_10168'},
json={'fields': {'customfield_10168': {'value': 'Asia', 'child': {'value': 'Romania'}}}},
)
print(r.status_code, r.text)Response: HTTP 400
{
"errorMessages": [],
"errors": {
"customfield_10168": "Specify a valid child option 'name' for zz-ref cascading"
}
}Sent to Atlassian Cloud on .
GET /rest/api/3/field/customfield_10168/context/10346/option
Parent and child options are listed together; children carry the id of their parent in optionId.
curl
curl \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
'https://your-domain.atlassian.net/rest/api/3/field/customfield_10168/context/10346/option'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/field/customfield_10168/context/10346/option',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"total": 4,
"values": [
{
"id": "10047",
"value": "Europe",
"disabled": false
},
{
"id": "10048",
"value": "Asia",
"disabled": false
},
{
"id": "10049",
"value": "Romania",
"optionId": "10047",
"disabled": false
},
{
"id": "10050",
"value": "France",
"optionId": "10047",
"disabled": false
}
]
}Sent to Atlassian Cloud on .
POST /rest/api/3/search/jql
A cascadeOption search for Europe and Romania returned no work item after the parent-only edit.
curl
curl -X POST \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"jql": "project = ZZREF AND \"zz-ref cascading\" in cascadeOption(Europe, Romania)",
"fields": [
"summary"
],
"maxResults": 2
}' \
'https://your-domain.atlassian.net/rest/api/3/search/jql'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.post(
'https://your-domain.atlassian.net/rest/api/3/search/jql',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
json={'jql': 'project = ZZREF AND "zz-ref cascading" in cascadeOption(Europe, Romania)',
'fields': ['summary'],
'maxResults': 2},
)
print(r.status_code, r.text)Response: HTTP 200
{
"issues": [],
"isLast": true
}Sent to Atlassian Cloud on .
POST /rest/api/3/search/jql
The same search matches once the work item holds Europe with Romania.
curl
curl -X POST \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"jql": "project = ZZREF AND \"zz-ref cascading\" in cascadeOption(Europe, Romania)",
"fields": [
"summary"
],
"maxResults": 2
}' \
'https://your-domain.atlassian.net/rest/api/3/search/jql'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.post(
'https://your-domain.atlassian.net/rest/api/3/search/jql',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
json={'jql': 'project = ZZREF AND "zz-ref cascading" in cascadeOption(Europe, Romania)',
'fields': ['summary'],
'maxResults': 2},
)
print(r.status_code, r.text)Response: HTTP 200
{
"issues": [
{
"key": "ZZREF-11"
}
],
"isLast": true
}Sent to Atlassian Cloud on .
POST /rest/api/3/search/jql
cascadeOption with the parent only also matches a work item that has a child.
curl
curl -X POST \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"jql": "project = ZZREF AND \"zz-ref cascading\" in cascadeOption(Europe)",
"fields": [
"summary"
],
"maxResults": 2
}' \
'https://your-domain.atlassian.net/rest/api/3/search/jql'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.post(
'https://your-domain.atlassian.net/rest/api/3/search/jql',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
json={'jql': 'project = ZZREF AND "zz-ref cascading" in cascadeOption(Europe)',
'fields': ['summary'],
'maxResults': 2},
)
print(r.status_code, r.text)Response: HTTP 200
{
"issues": [
{
"key": "ZZREF-11"
}
],
"isLast": true
}Sent to Atlassian Cloud on .
How it behaves
- Type key com.atlassian.jira.plugin.system.customfieldtypes:cascadingselect, searcher key com.atlassian.jira.plugin.system.customfieldtypes:cascadingselectsearcher, schema type option-with-child, display name "Select List (cascading)".
- {"value": "Europe", "child": {"value": "Romania"}} answered 200 and read back as the parent option with a child option inside it.
- {"value": "Europe"} alone answered 200 and the response had no child key.
- A child that is not under the parent gave 400 "Specify a valid child option 'name' for zz-ref cascading".
- cascadeOption(Europe, Romania) answered 200 with an empty list while the work item held only the parent, and matched once Europe with Romania was stored; cascadeOption(Europe) matched the work item that held Europe with the child Romania.
Pitfalls
- The error says child option 'name' although the working key is value; use value for both levels.
- Setting the parent alone wipes any child that was stored before.
- Parent and child options live in the same options list, where each child carries the id of its parent.
Questions and answers
Do I have to send the child?
No. The parent alone was accepted with 200, and the stored value then has no child.
Why did the first cascading JQL return nothing?
In that run the stored value was the parent alone. The same search matched in a later run where Europe and Romania were both stored.
Related
- Select list (single choice)
- Select list (multiple choices)
- Options of select and cascading fields
- JQL on custom fields
- Which fields can be set: editmeta and createmeta