Jira Cloud fields and work types
Jira sub-task work items via API: parent, hierarchy level
A sub-task is a work item of a sub-task work type (subtask true, hierarchyLevel -1) and it must name a parent in the same create call. The parent comes back on the child as a short object, and the parent lists its children under fields.subtasks.
Endpoints
| Method | Path | What it does |
|---|---|---|
POST | /rest/api/3/issue | Creates a work item, including a sub-task when parent is set. |
GET | /rest/api/3/issue/{issueIdOrKey} | Reads parent on a sub-task or subtasks on its parent. |
DELETE | /rest/api/3/issue/{issueIdOrKey} | Deletes a work item; sub-tasks need deleteSubtasks. |
Examples
POST /rest/api/3/issue
Creates a sub-task by work type name with the parent given by key. The answer is 201 with id, key and self.
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": "Sub-task"
},
"parent": {
"key": "{issueIdOrKey}"
},
"summary": "Sub-task example"
}
}' \
'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': 'Sub-task'},
'parent': {'key': '{issueIdOrKey}'},
'summary': 'Sub-task example'}},
)
print(r.status_code, r.text)Response: HTTP 201
{
"id": "10787",
"key": "ZZREF-8",
"self": "https://your-domain.atlassian.net/rest/api/3/issue/10787"
}Response headers
X-Ratelimit-Limit: 200
X-Ratelimit-Remaining: 199Sent to Atlassian Cloud on .
POST /rest/api/3/issue
Creates a sub-task without a parent. The 400 is keyed on issuetype.
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": "Sub-task"
},
"summary": "No parent"
}
}' \
'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': 'Sub-task'},
'summary': 'No parent'}},
)
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/issue/{issueIdOrKey}
Reads the sub-task with fields=parent,issuetype. The parent object carries its own summary, status, priority and work type.
curl
curl -G \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
--data-urlencode 'fields=parent,issuetype' \
'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': 'parent,issuetype'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-8",
"fields": {
"issuetype": {
"name": "Sub-task",
"subtask": true,
"hierarchyLevel": -1
},
"parent": {
"id": "10785",
"key": "ZZREF-6",
"fields": {
"summary": "Fields reference test issue",
"issuetype": {
"name": "Task",
"subtask": false
}
}
}
}
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/{issueIdOrKey}
Reads the parent with fields=subtasks. It lists each child with key, summary, status and work type.
curl
curl -G \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
--data-urlencode 'fields=subtasks' \
'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': 'subtasks'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"fields": {
"subtasks": [
{
"key": "ZZREF-8",
"fields": {
"summary": "Sub-task example",
"issuetype": {
"name": "Sub-task",
"subtask": true,
"hierarchyLevel": -1
}
}
}
]
}
}Sent to Atlassian Cloud on .
DELETE /rest/api/3/issue/{issueIdOrKey}
Deletes the sub-task. Without the Delete issues permission in the project the call fails with 403.
curl
curl -X DELETE \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.delete(
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)Response: HTTP 403
{
"errorMessages": [
"You do not have permission to delete issues in this project."
],
"errors": {}
}Sent to Atlassian Cloud on .
How it behaves
- A create with issuetype name 'Sub-task' and parent {key} answered 201 with id, key and self.
- Without a parent the create answered 400 with errors.issuetype = 'Issue type is a sub-task but parent issue key or id not specified.'.
- On the child, issuetype had subtask true and hierarchyLevel -1, and parent held id, key, self and a fields object with summary, status, priority and issuetype of the parent.
- The delete answered 403 with 'You do not have permission to delete issues in this project.'; the outcome depends on the Delete issues permission of the caller in that project.
Pitfalls
- Setting parent on a Task whose parent would also be a Task is refused, because the hierarchy is fixed by the work types; see the change page.
- The spec says a work item with sub-tasks cannot be deleted unless deleteSubtasks is true. That path was not run, since the permission to delete was missing.
- The name Sub-task belongs to the shared type; other projects may name theirs Subtask, so use the id from the project's work type list.
Questions and answers
Do I need the parent in the same request that creates the sub-task?
Yes. A sub-task work type requires parent as a key or id on create, and the error without it names the issuetype.
How do I list the sub-tasks of a work item?
Read fields=subtasks on the parent. Each entry has key, summary, status and work type.
Related
- parent
- List work types
- Change the work type
- Work type by id or by name
- issuetype
- Team-managed vs company-managed projects