Jira Cloud fields and work types
Jira issuetype field: set the work type through the API
issuetype carries the work type (issue type in the API). Create takes {"id": ...} or {"name": ...}, and it is the required field that decides which other fields exist. The type must belong to the project's scheme, and changing it on an existing item through the field is a different, restricted operation.
Endpoints
| Method | Path | What it does |
|---|---|---|
POST | /rest/api/3/issue | Creates a work item with fields.issuetype by id or name. |
PUT | /rest/api/3/issue/{issueIdOrKey} | An edit that sets fields.issuetype is checked against the hierarchy rules. |
GET | /rest/api/3/issue/{issueIdOrKey}/editmeta | Lists issuetype as required with no operations. |
Examples
POST /rest/api/3/issue
Creates a work item giving the project and the work type 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": {
"id": "{projectId}"
},
"issuetype": {
"id": "{issueTypeId}"
},
"summary": "Type given by id"
}
}' \
'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': {'id': '{projectId}'},
'issuetype': {'id': '{issueTypeId}'},
'summary': 'Type given by id'}},
)
print(r.status_code, r.text)Response: HTTP 201
{
"id": "10788",
"key": "ZZREF-9",
"self": "https://your-domain.atlassian.net/rest/api/3/issue/10788"
}Sent to Atlassian Cloud on .
POST /rest/api/3/issue
Leaves out the work type on create.
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"
},
"summary": "no type"
}
}' \
'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'}, 'summary': 'no type'}},
)
print(r.status_code, r.text)Response: HTTP 400
{
"errorMessages": [],
"errors": {
"issuetype": "Specify an issue type"
}
}Sent to Atlassian Cloud on .
POST /rest/api/3/issue
Names a work type that is not part of the project's scheme.
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": "Bug"
},
"summary": "x"
}
}' \
'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': 'Bug'}, 'summary': 'x'}},
)
print(r.status_code, r.text)Response: HTTP 400
{
"errorMessages": [],
"errors": {
"issuetype": "Specify a valid issue type"
}
}Sent to Atlassian Cloud on .
PUT /rest/api/3/issue/{otherIssueKey}
Edits an existing Task into a Sub-task by name.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"issuetype": {
"name": "Sub-task"
}
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{otherIssueKey}'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.put(
'https://your-domain.atlassian.net/rest/api/3/issue/{otherIssueKey}',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
json={'fields': {'issuetype': {'name': 'Sub-task'}}},
)
print(r.status_code, r.text)Response: HTTP 400
{
"errorMessages": [],
"errors": {
"issuetype": "Issue type is a sub-task but parent issue key or id not specified."
}
}Sent to Atlassian Cloud on .
GET /rest/api/3/issuetype/{issueTypeId}
Reads the work type itself: the id, whether it is a sub-task and its hierarchy level.
curl
curl \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
'https://your-domain.atlassian.net/rest/api/3/issuetype/{issueTypeId}'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/issuetype/{issueTypeId}',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"id": "10117",
"name": "Task",
"description": "A small, distinct piece of work.",
"subtask": false,
"hierarchyLevel": 0
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/{issueIdOrKey}/editmeta
The edit metadata marks issuetype as required and lists no operation.
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": {
"issuetype": {
"required": true,
"schema": {
"type": "issuetype",
"system": "issuetype"
},
"operations": [],
"allowedValues": [
{
"id": "10117",
"name": "Task",
"subtask": false,
"hierarchyLevel": 0
}
]
}
}
}Sent to Atlassian Cloud on .
How it behaves
- On create the work type may be given by id or by name, and both answered 201 (issue-create-type-by-id, issue-create-subtask).
- Without issuetype, create answered 400 with errors.issuetype set to Specify an issue type (sys-create-required-missing-type).
- A work type that is not in the project's scheme answered 400 with Specify a valid issue type (issue-create-type-other-project).
- Moving a Task to the sub-task type with a PUT answered 400 because no parent was given. The field is listed with an empty operations array in editmeta (issue-change-type-to-subtask, editmeta-zz).
Pitfalls
- Work type names are defined per site and scheme. Look up the id from the project's create metadata when the name can change or be translated.
- A sub-task type needs a parent on create, and the same message appears when an edit tries to turn a Task into a sub-task.
- The edit metadata lists no operation for issuetype, so do not build a general edit form around it. Check the error body on the call you send.
Questions and answers
Should I send the work type by id or by name?
Both worked on create. An id is stable if someone renames the type, a name is easier to read in a script.
Why is the field called issuetype when the UI says work type?
The API keeps the older names. Jira now says work item and work type in the UI, and the paths and field ids still use issue and issuetype.
Related
- parent
- List work types
- Sub-task work types
- Change the work type
- Work type by id or by name
- Which fields can be set: editmeta and createmeta