Jira Cloud fields and work types
Jira multi-select custom field: set, add and read via API
The multiple choice select list takes an array of option objects and reads back as an array. Edit metadata lists the operations add, set and remove, so values can be appended through the update block instead of overwriting the whole list.
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. |
GET | /rest/api/3/issue/{issueIdOrKey}/editmeta | Lists what can be edited. |
Examples
PUT /rest/api/3/issue/{issueIdOrKey}
Replaces the whole selection with two options given by value.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"customfield_10165": [
{
"value": "Red"
},
{
"value": "Blue"
}
]
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10165'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_10165',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'customfield_10165'},
json={'fields': {'customfield_10165': [{'value': 'Red'}, {'value': 'Blue'}]}},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-6",
"fields": {
"customfield_10165": [
{
"self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10039",
"value": "Red",
"id": "10039"
},
{
"self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10041",
"value": "Blue",
"id": "10041"
}
]
}
}Sent to Atlassian Cloud on .
PUT /rest/api/3/issue/{issueIdOrKey}
A single object in place of an array gives a 400.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"customfield_10165": {
"value": "Red"
}
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10165'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_10165',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'customfield_10165'},
json={'fields': {'customfield_10165': {'value': 'Red'}}},
)
print(r.status_code, r.text)Response: HTTP 400
{
"errorMessages": [],
"errors": {
"zz-ref multiselect": "Specify the value for zz-ref multiselect in an array"
}
}Sent to Atlassian Cloud on .
PUT /rest/api/3/issue/{issueIdOrKey}
Appends one option with an update block, leaving the others in place.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"update": {
"customfield_10165": [
{
"add": {
"value": "Green"
}
}
]
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10165'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_10165',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'customfield_10165'},
json={'update': {'customfield_10165': [{'add': {'value': 'Green'}}]}},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-6",
"fields": {
"customfield_10165": [
{
"self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10039",
"value": "Red",
"id": "10039"
},
{
"self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10040",
"value": "Green",
"id": "10040"
},
{
"self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10041",
"value": "Blue",
"id": "10041"
}
]
}
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/{issueIdOrKey}/editmeta
Edit metadata lists add, set and remove for the field and the options it accepts.
curl
curl \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/editmeta'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}/editmeta',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"fields": {
"customfield_10165": {
"name": "zz-ref multiselect",
"operations": [
"add",
"set",
"remove"
],
"allowedValues": [
{
"value": "Red",
"id": "10039"
},
{
"value": "Green",
"id": "10040"
},
{
"value": "Blue",
"id": "10041"
}
]
}
}
}Sent to Atlassian Cloud on .
How it behaves
- Type key com.atlassian.jira.plugin.system.customfieldtypes:multiselect, searcher key com.atlassian.jira.plugin.system.customfieldtypes:multiselectsearcher, schema type array with items option, display name "Select List (multiple choices)".
- [{"value": "Red"}, {"value": "Blue"}] answered 200 and the field came back as the two option objects with their ids.
- {"value": "Red"} without the array gave 400 "Specify the value for zz-ref multiselect in an array", and the key in errors is the display name there, not the field id.
- {"update": {"customfield_10165": [{"add": {"value": "Green"}}]}} kept Red and Blue and returned all three; the order followed the option order (Red, Green, Blue), not the order of insertion.
Pitfalls
- Using fields replaces the list. To keep what is already there, use the update block with add or remove.
- The error for a single object is keyed by the display name, unlike most other errors that are keyed by the field id.
- Order in the response follows the option list, so do not rely on it to reflect the order in which values were added.
Questions and answers
How do I add one option without losing the others?
Use update with an add operation: the run kept Red and Blue and added Green.
What does a multi-select reject?
A single object where an array is expected; the response is a 400 saying the value must be in an array.
Related
- Checkboxes
- Select list (single choice)
- Labels (custom)
- Options of select and cascading fields
- Which fields can be set: editmeta and createmeta