Jira Cloud fields and work types
Jira custom field default values: read and set via API
Defaults belong to a context. GET /rest/api/3/field/{fieldId}/context/defaultValue lists one object per context, and PUT sets them with a body typed by field kind, for example option.single with an optionId. The create metadata for the project then shows hasDefaultValue and the value.
Endpoints
| Method | Path | What it does |
|---|---|---|
GET | /rest/api/3/field/{fieldId}/context/defaultValue | Lists the base default of each context of a field. |
PUT | /rest/api/3/field/{fieldId}/context/defaultValue | Sets the default of one or more contexts. |
GET | /rest/api/3/issue/createmeta/{projectIdOrKey}/issuetypes/{issueTypeId} | Shows hasDefaultValue and defaultValue for each field on create. |
Examples
GET /rest/api/3/field/customfield_10164/context
The context ids needed for the default come from the context list. Pick the project context, not the global one.
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'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',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"values": [
{
"id": "10337",
"isGlobalContext": true
},
{
"id": "10338",
"isGlobalContext": false
}
]
}Sent to Atlassian Cloud on .
GET /rest/api/3/field/customfield_10204/context/defaultValue
Reads the defaults of a select list field before any is set. Each context has an object with only type and contextId, which is how an unset default looks.
curl
curl \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
'https://your-domain.atlassian.net/rest/api/3/field/customfield_10204/context/defaultValue'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/field/customfield_10204/context/defaultValue',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"maxResults": 50,
"startAt": 0,
"total": 2,
"isLast": true,
"values": [
{
"type": "option.single",
"contextId": "10417"
},
{
"type": "option.single",
"contextId": "10418"
}
]
}Sent to Atlassian Cloud on .
PUT /rest/api/3/field/customfield_10204/context/defaultValue
Sets the third option as the default of the project context. The body names the context, the option id and the type option.single; the answer is 204.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"defaultValues": [
{
"contextId": "10418",
"optionId": "10069",
"type": "option.single"
}
]
}' \
'https://your-domain.atlassian.net/rest/api/3/field/customfield_10204/context/defaultValue'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.put(
'https://your-domain.atlassian.net/rest/api/3/field/customfield_10204/context/defaultValue',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
json={'defaultValues': [{'contextId': '10418', 'optionId': '10069', 'type': 'option.single'}]},
)
print(r.status_code, r.text)Response: HTTP 204
No response body.
Response headers
X-Ratelimit-Limit: 300
X-Ratelimit-Remaining: 299Sent to Atlassian Cloud on .
GET /rest/api/3/field/customfield_10204/context/defaultValue
Reads the defaults again. The project context now has optionId, the global one is still unset.
curl
curl \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
'https://your-domain.atlassian.net/rest/api/3/field/customfield_10204/context/defaultValue'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/field/customfield_10204/context/defaultValue',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"maxResults": 50,
"startAt": 0,
"total": 2,
"isLast": true,
"values": [
{
"type": "option.single",
"contextId": "10417"
},
{
"type": "option.single",
"contextId": "10418",
"optionId": "10069"
}
]
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/createmeta/ZZREF/issuetypes/{issueTypeId}
Create metadata shows the same default from the work item side. The select list field has hasDefaultValue true and defaultValue set to the option, while fields without a default show false.
curl
curl -G \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
--data-urlencode 'maxResults=60' \
'https://your-domain.atlassian.net/rest/api/3/issue/createmeta/ZZREF/issuetypes/{issueTypeId}'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/issue/createmeta/ZZREF/issuetypes/{issueTypeId}',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'maxResults': '60'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"fields": [
{
"fieldId": "assignee",
"hasDefaultValue": false
},
{
"fieldId": "attachment",
"hasDefaultValue": false
},
{
"fieldId": "customfield_10001",
"hasDefaultValue": false
},
{
"fieldId": "customfield_10015",
"hasDefaultValue": false
},
{
"fieldId": "customfield_10142",
"hasDefaultValue": false
},
{
"fieldId": "customfield_10162",
"hasDefaultValue": false
},
{
"fieldId": "customfield_10163",
"hasDefaultValue": false
},
{
"fieldId": "customfield_10164",
"hasDefaultValue": true,
"defaultValue": {
"self": "https://your-domain.atlassian.net/rest/api/3/customFieldOption/10037",
"value": "Green",
"id": "10037"
}
}
]
}Sent to Atlassian Cloud on .
How it behaves
- Before any default was set, the read returned two objects, one per context, each with type option.single and contextId and nothing else. That matches the spec: an unset default is an object with the type and contextId and no value properties.
- PUT with defaultValues [{contextId, optionId, type: 'option.single'}] answered 204 and no body.
- The read after the PUT showed optionId on the context that was set and an unchanged bare object on the other one.
- In create metadata the select field showed hasDefaultValue true and defaultValue with the self link, value 'Green' and id of the option. The system priority field also showed hasDefaultValue true in the same listing.
Pitfalls
- The body type depends on the field kind: option.single for single choice selects and radio buttons, option.multiple for multiple choice selects and checkboxes, option.cascading, datepicker, datetimepicker, and user and group picker types, all listed in the spec.
- A field with several contexts has one default per context, so setting the project context leaves the global context unset.
- Read the defaults back with GET after a PUT; the 204 has no body and does not confirm which option was stored.
Questions and answers
Does a default change work items that already exist?
The runs did not test this. The default is reported through the defaults read and through create metadata, which is what a new work item is built from.
Where do I read the current default of a field?
GET /rest/api/3/field/{fieldId}/context/defaultValue lists the base default per context, and the create metadata shows hasDefaultValue and defaultValue for the project.
Related
- Custom field contexts
- Options of select and cascading fields
- Which fields can be set: editmeta and createmeta
- Select list (single choice)
- Date picker
- Radio buttons