Jira Cloud fields and work types
Jira parent field: sub-tasks and parent links via the API
parent links a work item to the item above it in the hierarchy. A sub-task needs it on create, and it reads back as a small object with the parent's summary, status, priority and work type. Two real errors: a sub-task without a parent, and a Task given another Task as its parent.
Endpoints
| Method | Path | What it does |
|---|---|---|
POST | /rest/api/3/issue | Creates a sub-task with fields.parent as {"key": ...}. |
PUT | /rest/api/3/issue/{issueIdOrKey} | Sets or changes fields.parent. A parent in the wrong hierarchy answers 400. |
GET | /rest/api/3/issue/{issueIdOrKey} | Returns parent on the child and subtasks on the parent. |
Examples
POST /rest/api/3/issue
Creates a sub-task under a parent by key.
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"
}Sent to Atlassian Cloud on .
POST /rest/api/3/issue
Creates a sub-task and leaves the parent out.
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 .
PUT /rest/api/3/issue/{issueIdOrKey}
Sets another Task as the parent of a Task.
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}
Reads the child with the parent field. The parent is summarised, not returned in full.
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": {
"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 the subtasks field, the other direction of the same link.
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 .
GET /rest/api/3/issue/{issueIdOrKey}/editmeta
The edit metadata lists parent with the issuelink schema and the set 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": {
"parent": {
"required": false,
"schema": {
"type": "issuelink",
"system": "parent"
},
"name": "Parent",
"key": "parent",
"hasDefaultValue": false,
"operations": [
"set"
]
}
}
}Sent to Atlassian Cloud on .
How it behaves
- A Sub-task created with parent {"key": ...} answered 201 (issue-create-subtask).
- Without a parent, create answered 400 with errors.issuetype set to Issue type is a sub-task but parent issue key or id not specified (issue-create-subtask-no-parent).
- Giving a Task a Task as parent answered 400 with the message Given parent work item does not belong to appropriate hierarchy and an errors.pid entry (sys-parent-on-task).
- The child reads parent as id, key, self and a small fields object. The parent reads subtasks as the reverse list. Sub-task hierarchyLevel is -1 and Task is 0 (issue-subtask-get, issue-parent-subtasks).
Pitfalls
- The parent field and the sub-task type go together. Give both on create, or the error names issuetype and not parent.
- The errors.pid message talks about the same project, while the main message talks about hierarchy. Read both before deciding what to change.
- Parent objects are partial. Fetch the parent with its own GET when more than summary, status and priority are needed.
Questions and answers
Do I send parent by id or by key?
The runs used the key. The OpenAPI text for the edit call says the parent may be set by key or id.
How do I find the sub-tasks of an item?
Read the subtasks field of the parent. It lists id, key, URL and a small fields object for each child.
Related
- Sub-task work types
- issuetype
- Change the work type
- List work types
- summary
- Reading field values: names, schema, v2 and v3