Going Stellar

Home/Jira fields reference

Jira Cloud fields and work types

Jira priority field: set by name and read back

priority is a single-choice system field. It is set with an object that names the priority, and it reads back as an object with self, iconUrl, name and id. A name that is not in the site's priority list answers 400 with a message that talks about the string format.

Endpoints

MethodPathWhat it does
PUT/rest/api/3/issue/{issueIdOrKey}Sets fields.priority by name or id.
POST/rest/api/3/issueAccepts fields.priority by id on create.
GET/rest/api/3/issue/{issueIdOrKey}Returns fields.priority as an object.
GET/rest/api/3/issue/{issueIdOrKey}/editmetaLists allowedValues for the priority field.
GET/rest/api/3/priority/searchLists the priorities of the site.

Examples

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

Sets the priority to High and asks for the edited field in the response.

curl

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

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

Response: HTTP 200

{
 "key": "ZZREF-6",
 "fields": {
  "priority": {
   "self": "https://your-domain.atlassian.net/rest/api/3/priority/2",
   "iconUrl": "https://your-domain.atlassian.net/images/icons/priorities/high_new.svg",
   "name": "High",
   "id": "2"
  }
 }
}

Sent to Atlassian Cloud on .

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

Sends a priority name that does not exist.

curl

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

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

Response: HTTP 400

{
 "errorMessages": [],
 "errors": {
  "priority": "Specify the Priority (name) in the string format"
 }
}

Sent to Atlassian Cloud on .

GET /rest/api/3/issue/{issueIdOrKey}/editmeta

The edit metadata lists the choices the caller may set, with ids.

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": {
  "priority": {
   "required": false,
   "schema": {
    "type": "priority",
    "system": "priority"
   },
   "name": "Priority",
   "operations": [
    "set"
   ],
   "allowedValues": [
    {
     "id": "1",
     "name": "Highest"
    },
    {
     "id": "2",
     "name": "High"
    },
    {
     "id": "3",
     "name": "Medium"
    }
   ]
  }
 }
}

Sent to Atlassian Cloud on .

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

Reads the priority alongside other system fields, as part of an ordinary GET.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'fields=priority,duedate,labels,components,fixVersions,environment,timetracking,reporter,status,resolution,issuetype,project,created,updated' \
  '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': 'priority,duedate,labels,components,fixVersions,environment,timetracking,reporter,status,resolution,issuetype,project,created,updated'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "key": "ZZREF-6",
 "fields": {
  "priority": {
   "self": "https://your-domain.atlassian.net/rest/api/3/priority/2",
   "iconUrl": "https://your-domain.atlassian.net/images/icons/priorities/high_new.svg",
   "name": "High",
   "id": "2"
  }
 }
}

Sent to Atlassian Cloud on .

GET /rest/api/3/priority/search

Lists the priorities of the site, with ids, names and the default flag.

curl

curl \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  'https://your-domain.atlassian.net/rest/api/3/priority/search'

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "total": 5,
 "values": [
  {
   "id": "1",
   "name": "Highest",
   "isDefault": false
  },
  {
   "id": "2",
   "name": "High",
   "isDefault": false
  },
  {
   "id": "3",
   "name": "Medium",
   "isDefault": false
  }
 ]
}

Sent to Atlassian Cloud on .

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

Sets the priority by id instead of name.

curl

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

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

Response: HTTP 200

{
 "key": "ZZREF-11",
 "fields": {
  "priority": {
   "self": "https://your-domain.atlassian.net/rest/api/3/priority/1",
   "iconUrl": "https://your-domain.atlassian.net/images/icons/priorities/highest_new.svg",
   "name": "Highest",
   "id": "1"
  }
 }
}

Sent to Atlassian Cloud on .

POST /rest/api/3/issue

Creates a work item with the priority given by id.

curl

curl -X POST \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "fields": {
    "project": {
      "key": "ZZREF"
    },
    "issuetype": {
      "name": "Task"
    },
    "summary": "Priority by id",
    "priority": {
      "id": "{priorityId}"
    }
  }
}' \
  'https://your-domain.atlassian.net/rest/api/3/issue'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.post(
    'https://your-domain.atlassian.net/rest/api/3/issue',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    json={'fields': {'project': {'key': 'ZZREF'},
                     'issuetype': {'name': 'Task'},
                     'summary': 'Priority by id',
                     'priority': {'id': '{priorityId}'}}},
)
print(r.status_code, r.text)

Response: HTTP 201

{
 "id": "10792",
 "key": "ZZREF-13",
 "self": "https://your-domain.atlassian.net/rest/api/3/issue/10792"
}

Sent to Atlassian Cloud on .

How it behaves

  • {"priority": {"name": "High"}} answered 200. The response held the priority object with id 2 and name High (sys-priority).
  • An unknown name answered 400 with errors.priority set to Specify the Priority (name) in the string format, even though the request used an object (sys-priority-bad).
  • The edit metadata lists priority with the set operation and an allowedValues array whose first values are Highest, High and Medium (editmeta-zz).
  • {"priority": {"id": ...}} answered 200 on edit and 201 on create (sys-priority-id, sys-create-with-priority-id).
  • GET /rest/api/3/priority/search listed 5 priorities with id, name and isDefault (priorities-list).

Pitfalls

  • The error text suggests a string is wanted. The cause in the run was the unknown name, so check the allowed values first.
  • Priority names come from the site's priority list. A script that hard-codes High may fail where the list differs, so read allowedValues when portability matters.
  • Ids are strings in the responses ("2"), so send them as strings.

Questions and answers

How do I find the valid priority names?

Read allowedValues for priority from the edit metadata of a work item, or from the create metadata for the project and work type.

What does the priority look like when read?

An object with self, iconUrl, name and id. The name and id are the values to compare.

Sources

  1. Issues (Jira REST API v3)
  2. Edit issue (Jira REST API v3)
  3. Get issue (Jira REST API v3)
  4. Get edit issue metadata (Jira REST API v3)

Markdown version · All Jira fields pages