Going Stellar

Home/Jira fields reference

Jira Cloud fields and work types

Jira select list custom field: set and read via API

The single choice select list takes an object with either value or id and reads back as an option object with self, value and id. A bare string is refused, as is a value that is not one of the options. Setting null clears it.

Endpoints

MethodPathWhat 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/jqlFinds work items by value.
GET/rest/api/3/field/{fieldId}/context/{contextId}/optionLists the options.

Examples

PUT /rest/api/3/issue/{issueIdOrKey}

Sets the field by option text.

curl

curl -X PUT \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "fields": {
    "customfield_10164": {
      "value": "Red"
    }
  }
}' \
  'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10164'

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_10164',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'returnIssue': 'true', 'fields': 'customfield_10164'},
    json={'fields': {'customfield_10164': {'value': 'Red'}}},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "key": "ZZREF-6",
 "fields": {
  "customfield_10164": {
   "self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10036",
   "value": "Red",
   "id": "10036"
  }
 }
}

Sent to Atlassian Cloud on .

PUT /rest/api/3/issue/{issueIdOrKey}

Sets it by option id, the safer form when option names can change.

curl

curl -X PUT \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "fields": {
    "customfield_10164": {
      "id": "10037"
    }
  }
}' \
  'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10164'

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_10164',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'returnIssue': 'true', 'fields': 'customfield_10164'},
    json={'fields': {'customfield_10164': {'id': '10037'}}},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "key": "ZZREF-6",
 "fields": {
  "customfield_10164": {
   "self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10037",
   "value": "Green",
   "id": "10037"
  }
 }
}

Sent to Atlassian Cloud on .

PUT /rest/api/3/issue/{issueIdOrKey}

An option text that is not in the list gives a 400 that says to specify a valid value.

curl

curl -X PUT \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "fields": {
    "customfield_10164": {
      "value": "Purple"
    }
  }
}' \
  'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10164'

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_10164',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'returnIssue': 'true', 'fields': 'customfield_10164'},
    json={'fields': {'customfield_10164': {'value': 'Purple'}}},
)
print(r.status_code, r.text)

Response: HTTP 400

{
 "errorMessages": [],
 "errors": {
  "customfield_10164": "Specify a valid value for zz-ref select"
 }
}

Sent to Atlassian Cloud on .

PUT /rest/api/3/issue/{issueIdOrKey}

A bare string is not an option object.

curl

curl -X PUT \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "fields": {
    "customfield_10164": "Red"
  }
}' \
  'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10164'

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_10164',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'returnIssue': 'true', 'fields': 'customfield_10164'},
    json={'fields': {'customfield_10164': 'Red'}},
)
print(r.status_code, r.text)

Response: HTTP 400

{
 "errorMessages": [],
 "errors": {
  "customfield_10164": "Specify a valid 'id' or 'name' for zz-ref select"
 }
}

Sent to Atlassian Cloud on .

PUT /rest/api/3/issue/{issueIdOrKey}

Writing null clears the field and the response shows null.

curl

curl -X PUT \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "fields": {
    "customfield_10164": null
  }
}' \
  'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10164'

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_10164',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'returnIssue': 'true', 'fields': 'customfield_10164'},
    json={'fields': {'customfield_10164': None}},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "key": "ZZREF-6",
 "fields": {
  "customfield_10164": null
 }
}

Sent to Atlassian Cloud on .

POST /rest/api/3/search/jql

Finds work items by option text; the quoted name and the = operator are enough.

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 select\" = Green",
  "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 select" = Green',
          'fields': ['summary'],
          'maxResults': 2},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "issues": [
  {
   "key": "ZZREF-9"
  },
  {
   "key": "ZZREF-8"
  }
 ],
 "isLast": false
}

Sent to Atlassian Cloud on .

GET /rest/api/3/field/customfield_10164/context/10338/option

Option ids come from the options endpoint of the field context.

curl

curl \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  'https://your-domain.atlassian.net/rest/api/3/field/customfield_10164/context/10338/option'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/rest/api/3/field/customfield_10164/context/10338/option',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "total": 3,
 "values": [
  {
   "id": "10036",
   "value": "Red",
   "disabled": false
  },
  {
   "id": "10037",
   "value": "Green",
   "disabled": false
  },
  {
   "id": "10038",
   "value": "Blue",
   "disabled": false
  }
 ]
}

Sent to Atlassian Cloud on .

How it behaves

  • Type key com.atlassian.jira.plugin.system.customfieldtypes:select, searcher key com.atlassian.jira.plugin.system.customfieldtypes:multiselectsearcher, schema type option, display name "Select List (single choice)".
  • {"value": "Red"} and {"id": "10037"} both set the field with 200 and the response is {"self": ..., "value": ..., "id": ...}.
  • A value that is not an option gave 400 "Specify a valid value for zz-ref select"; a bare string gave 400 "Specify a valid 'id' or 'name' for zz-ref select".
  • {"fields": {"customfield_10164": null}} answered 200 with the field null.
  • The same option can be found with the quoted name and a value, or with cf[10164] and the option id; the id form returned the same first two work items.

Pitfalls

  • The error for a bare string mentions 'id' or 'name', yet the runs that worked used the keys id and value.
  • Adding a new option through the options endpoint is a separate step from setting a value on a work item.
  • JQL on an option field with a long result list pages with nextPageToken, so isLast=false is normal with a small maxResults.

Questions and answers

Do I set a select list by id or by value?

Either. {"id": "10037"} and {"value": "Green"} were both accepted with 200.

How do I empty a select list field?

Send null as the value; the work item came back with the field set to null.

Sources

  1. Issues (Jira REST API v3)
  2. Issue fields (Jira REST API v3)
  3. Issue custom field options (Jira REST API v3)

Markdown version · All Jira fields pages