Jira Cloud fields and work types
Jira version picker custom field: set by name via API
The version picker takes {"name": version name} and reads back as a version object with self, id, name, archived and released. Edit metadata lists the versions that can be chosen.
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}
Sets the field to a version by name.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"customfield_10179": {
"name": "zz-ref 1.0"
}
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10179'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_10179',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'customfield_10179'},
json={'fields': {'customfield_10179': {'name': 'zz-ref 1.0'}}},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-6",
"fields": {
"customfield_10179": {
"self": "https://your-domain.atlassian.net/rest/api/3/version/10002",
"id": "10002",
"name": "zz-ref 1.0",
"archived": false,
"released": false
}
}
}Sent to Atlassian Cloud on .
PUT /rest/api/3/issue/{issueIdOrKey}
A version that is not in the project is refused.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"customfield_10199": {
"name": "9.9"
}
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10199'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_10199',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'customfield_10199'},
json={'fields': {'customfield_10199': {'name': '9.9'}}},
)
print(r.status_code, r.text)Response: HTTP 400
{
"errorMessages": [],
"errors": {
"customfield_10199": "Specify a valid value for zz-ref version"
}
}Sent to Atlassian Cloud on .
POST /rest/api/3/search/jql
Finds work items by version name with =.
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 version\" = \"zz-ref 1.0\"",
"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 version" = "zz-ref 1.0"',
'fields': ['summary'],
'maxResults': 2},
)
print(r.status_code, r.text)Response: HTTP 200
{
"issues": [
{
"key": "ZZREF-11"
}
],
"isLast": true
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/{issueIdOrKey}
Reading returns the same version object.
curl
curl -G \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
--data-urlencode 'fields=customfield_10162,customfield_10163,customfield_10164,customfield_10165,customfield_10166,customfield_10167,customfield_10168,customfield_10169,customfield_10170,customfield_10171,customfield_10172,customfield_10173,customfield_10174,customfield_10175,customfield_10176,customfield_10177,customfield_10178,customfield_10179,customfield_10180,customfield_10181' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'fields': 'customfield_10162,customfield_10163,customfield_10164,customfield_10165,customfield_10166,customfield_10167,customfield_10168,customfield_10169,customfield_10170,customfield_10171,customfield_10172,customfield_10173,customfield_10174,customfield_10175,customfield_10176,customfield_10177,customfield_10178,customfield_10179,customfield_10180,customfield_10181'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-6",
"fields": {
"customfield_10179": {
"self": "https://your-domain.atlassian.net/rest/api/3/version/10002",
"id": "10002",
"name": "zz-ref 1.0",
"archived": false,
"released": false
}
}
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/{issueIdOrKey}/editmeta
Edit metadata lists the operation set and the first allowed versions.
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_10179": {
"name": "zz-ref version",
"operations": [
"set"
],
"allowedValues": [
{
"id": "10002",
"name": "zz-ref 1.0",
"released": false
},
{
"id": "10003",
"name": "zz-ref 2.0",
"released": false
}
]
}
}
}Sent to Atlassian Cloud on .
How it behaves
- Type key com.atlassian.jira.plugin.system.customfieldtypes:version, searcher key com.atlassian.jira.plugin.system.customfieldtypes:versionsearcher, schema type version, display name "Version Picker (single version)".
- {"name": "zz-ref 1.0"} answered 200 and read back as {"self": ..., "id": "10002", "name": ..., "archived": false, "released": false}.
- {"name": "9.9"} gave 400 "Specify a valid value for zz-ref version".
- "zz-ref version" = "zz-ref 1.0" matched; edit metadata lists only the operation set, and allowedValues holds the versions of the project.
Pitfalls
- The unknown-version message does not say which names are valid; read allowedValues from edit metadata.
- Archived and released versions come back with their flags; the run did not test whether archived versions can be chosen.
- Only a version name from the project of the work item was used in the run.
Questions and answers
Is the version set by name or id?
By name in the run, and the response returned the id and the archived and released flags.
Related
- Version picker (multiple)
- fixVersions
- Project picker
- Reading field values: names, schema, v2 and v3
- Which fields can be set: editmeta and createmeta