Jira Cloud fields and work types
Jira components field: set by name and read back
components is an array of project components. It is set with objects such as {"name": ...} and reads back with self, id and name for each. The component must already exist in the project.
Endpoints
| Method | Path | What it does |
|---|---|---|
PUT | /rest/api/3/issue/{issueIdOrKey} | Sets fields.components with component names. |
GET | /rest/api/3/issue/{issueIdOrKey} | Returns components as an array of objects. |
GET | /rest/api/3/field/search | Lists components among the system fields. |
Examples
PUT /rest/api/3/issue/{issueIdOrKey}
Assigns a component by name and reads the edited field back.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"components": [
{
"name": "zz-ref API"
}
]
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=components'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=components',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'components'},
json={'fields': {'components': [{'name': 'zz-ref API'}]}},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-6",
"fields": {
"components": [
{
"self": "https://your-domain.atlassian.net/rest/api/3/component/10000",
"id": "10000",
"name": "zz-ref API"
}
]
}
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/{issueIdOrKey}
Reads components with other system fields.
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": {
"components": [
{
"self": "https://your-domain.atlassian.net/rest/api/3/component/10000",
"id": "10000",
"name": "zz-ref API"
}
]
}
}Sent to Atlassian Cloud on .
GET /rest/api/3/field/search
The system field list: components has a component item type in its schema.
curl
curl -G \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
--data-urlencode 'type=system' \
--data-urlencode 'maxResults=5' \
'https://your-domain.atlassian.net/rest/api/3/field/search'Python (requests)
import os
import requests
EMAIL = "you@example.com"
r = requests.get(
'https://your-domain.atlassian.net/rest/api/3/field/search',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'type': 'system', 'maxResults': '5'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"values": [
{
"id": "versions",
"name": "Affects versions",
"schema": {
"type": "array",
"items": "version",
"system": "versions"
}
},
{
"id": "assignee",
"name": "Assignee",
"schema": {
"type": "user",
"system": "assignee"
}
},
{
"id": "attachment",
"name": "Attachment",
"schema": {
"type": "array",
"items": "attachment",
"system": "attachment"
}
},
{
"id": "comment",
"name": "Comment",
"schema": {
"type": "comments-page",
"system": "comment"
}
},
{
"id": "components",
"name": "Components",
"schema": {
"type": "array",
"items": "component",
"system": "components"
}
}
]
}Sent to Atlassian Cloud on .
GET /rest/api/3/issue/{issueIdOrKey}
Reads every navigable field and picks out components and fixVersions, which share the same array shape.
curl
curl -G \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
--data-urlencode 'fields=*navigable' \
'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': '*navigable'},
)
print(r.status_code, r.text)Response: HTTP 200
{
"fields": {
"components": [
{
"self": "https://your-domain.atlassian.net/rest/api/3/component/10000",
"id": "10000",
"name": "zz-ref API"
}
],
"fixVersions": [
{
"self": "https://your-domain.atlassian.net/rest/api/3/version/10002",
"id": "10002",
"name": "zz-ref 1.0",
"archived": false,
"released": false
}
]
}
}Sent to Atlassian Cloud on .
PUT /rest/api/3/issue/{issueIdOrKey}
Sets the component by id.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"components": [
{
"id": "{componentId}"
}
]
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=components'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=components',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'components'},
json={'fields': {'components': [{'id': '{componentId}'}]}},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-11",
"fields": {
"components": [
{
"self": "https://your-domain.atlassian.net/rest/api/3/component/10000",
"id": "10000",
"name": "zz-ref API"
}
]
}
}Sent to Atlassian Cloud on .
PUT /rest/api/3/issue/{issueIdOrKey}
Sets a component name that does not exist in the project.
curl
curl -X PUT \
-u "you@example.com:$ATLASSIAN_API_TOKEN" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
--data '{
"fields": {
"components": [
{
"name": "No such component"
}
]
}
}' \
'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=components'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=components',
auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
headers={'Accept': 'application/json'},
params={'returnIssue': 'true', 'fields': 'components'},
json={'fields': {'components': [{'name': 'No such component'}]}},
)
print(r.status_code, r.text)Response: HTTP 200
{
"key": "ZZREF-11",
"fields": {
"components": [
{
"self": "https://your-domain.atlassian.net/rest/api/3/component/10001",
"id": "10001",
"name": "No such component"
}
]
}
}Sent to Atlassian Cloud on .
How it behaves
- {"components": [{"name": "zz-ref API"}]} answered 200 and returned the component with its id and URL (sys-components).
- The write succeeded although the field did not appear in the edit metadata of the work item, which listed no components entry (sys-components, editmeta-zz).
- The schema is an array whose items are component, and the JQL name is component (fields-search-system, fields-all).
- {"id": ...} answered 200 and returned the same component (sys-components-id).
- An unknown name answered 200, not 400. The response shows a component with a new id, 10001, named No such component, so the call stored a new one (sys-components-bad).
Pitfalls
- fields.components is the set operation, so send the array you want the work item to end with. Read the current list first when other tools also edit components.
- A misspelled component name is not an error. It answered 200 and created a component with that name, so validate names against the project's component list first.
- Do not use the edit metadata as the list of writable fields for system fields on every screen. It left out components in the runs for this page.
Questions and answers
Can I send a component id instead of a name?
Yes. {"id": ...} answered 200 and returned the component with its name.
How is a component read back?
As an object with self, id and name for each entry, in an array.
Related
- fixVersions
- labels
- Which fields can be set: editmeta and createmeta
- Field ids, keys and names
- Fields on screens