Jira Cloud fields and work types
Change a Jira work item's work type via API: limits
The work type of an existing work item is a field called issuetype, and the edit metadata lists it with an empty operations array. A direct PUT that turns a Task into a sub-task fails without a parent, and with a Task as the parent it fails on the hierarchy. For larger moves the spec offers a bulk move endpoint.
Endpoints
| Method | Path | What it does |
|---|---|---|
PUT | /rest/api/3/issue/{issueIdOrKey} | Edits fields, including issuetype and parent. |
GET | /rest/api/3/issue/{issueIdOrKey}/editmeta | Shows whether issuetype is listed and which values it allows. |
GET | /rest/api/3/issuetype/{id}/alternatives | Lists work types that could replace one. |
POST | /rest/api/3/bulk/issues/move | Moves up to 1000 work items to one project, work type and parent. |
Examples
PUT /rest/api/3/issue/{otherIssueKey}
Changes a Task to the sub-task work type with no parent. The edit is refused and the message names the missing parent.
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 .
PUT /rest/api/3/issue/{otherIssueKey}
Sends the sub-task type and a parent in the same edit. The parent is a Task, and the edit is refused on the hierarchy.
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"
},
"parent": {
"key": "{issueIdOrKey}"
}
}
}' \
'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'}, 'parent': {'key': '{issueIdOrKey}'}}},
)
print(r.status_code, r.text)Response: HTTP 400
{
"errorMessages": [
"Given parent work item does not belong to appropriate hierarchy."
],
"errors": {
"pid": "Issues with this Issue Type must be created in the same project as the parent."
}
}Sent to Atlassian Cloud on .
PUT /rest/api/3/issue/{issueIdOrKey}
Sets a Task as the parent of another Task. The refusal is the same hierarchy message.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"parent": {
"key": "{otherIssueKey}"
}
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=parent'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=parent',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'parent'},
json={'fields': {'parent': {'key': '{otherIssueKey}'}}},
)
print(r.status_code, r.text)Response: HTTP 400
{
"errorMessages": [
"Given parent work item does not belong to appropriate hierarchy."
],
"errors": {
"pid": "Issues with this Issue Type must be created in the same project as the parent."
}
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/{issueIdOrKey}/editmeta
Edit metadata for the work type field. It is required, has no operations, and allows only the current type.
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,
"operations": [],
"allowedValues": [
{
"id": "10117",
"name": "Task",
"subtask": false
}
]
}
}
}Sent to Atlassian Cloud on .
GET /rest/api/3/issuetype/{issueTypeId}/alternatives
Asks for work types that can replace Task in the project. None are listed.
curl
curl \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
'https://your-domain.atlassian.net/rest/api/3/issuetype/{issueTypeId}/alternatives'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/issuetype/{issueTypeId}/alternatives',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)Response: HTTP 200
[]Sent to Atlassian Cloud on .
How it behaves
- Edit metadata listed issuetype with required true, operations [] and a single allowed value, Task.
- A PUT with fields.issuetype {name: 'Sub-task'} on a Task answered 400 with errors.issuetype = 'Issue type is a sub-task but parent issue key or id not specified.', the same text as a create without a parent.
- A PUT with a parent on a Task answered 400 with errorMessages ['Given parent work item does not belong to appropriate hierarchy.'] and errors.pid = 'Issues with this Issue Type must be created in the same project as the parent.'.
- With the sub-task type and a Task parent in one PUT the answer was 400 with 'Given parent work item does not belong to appropriate hierarchy.' and errors.pid = 'Issues with this Issue Type must be created in the same project as the parent.', although both work items were in the same project. The project has only Task and Sub-task, so no change between two base types could be tried.
Pitfalls
- The edit metadata lists no operations for issuetype, so do not build a client that relies on a plain PUT of the work type being supported; check the response.
- Turning a Task into a sub-task needs a parent in the same edit. A Task parent was still refused on the hierarchy, and the pid text about the same project is misleading when both are in one project.
- Bulk move is described in the spec as an early version without full parity with the Bulk Move screen.
Questions and answers
Can I convert a Task to a sub-task with the API?
A PUT with the sub-task type failed both without a parent and with a Task as parent in the runs, so no working PUT was observed.
How do I move many work items to another work type?
Use POST /rest/api/3/bulk/issues/move, which the spec describes for up to 1000 work items to one project, work type and parent.
Related
- issuetype
- Sub-task work types
- List work types
- Work type schemes
- parent
- Which fields can be set: editmeta and createmeta