Going Stellar

Home/Jira fields reference

Jira Cloud fields and work types

Jira work type by id or name when creating work items

When a work item is created, issuetype can be given as an object with an id or with a name, and both worked. Reading one work type is only possible by id, at GET /rest/api/3/issuetype/{id}. A missing type and a type not in the project give two different 400 messages.

Endpoints

MethodPathWhat it does
POST/rest/api/3/issueCreates a work item with fields.issuetype as {id} or {name}.
GET/rest/api/3/issuetype/{id}Reads one work type by id.

Examples

POST /rest/api/3/issue

Creates a Task with the project and work type given by id. The answer is 201.

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

The same call with the work type given by name, using the sub-task type with a parent.

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 .

GET /rest/api/3/issuetype/{issueTypeId}

Reads one work type by id. The object has name and untranslatedName, subtask, avatarId and hierarchyLevel.

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

{
 "self": "https://your-domain.atlassian.net/rest/api/3/issuetype/10117",
 "id": "10117",
 "description": "A small, distinct piece of work.",
 "iconUrl": "https://your-domain.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10318?size=medium",
 "name": "Task",
 "untranslatedName": "Task",
 "subtask": false,
 "avatarId": 10318,
 "hierarchyLevel": 0
}

Sent to Atlassian Cloud on .

POST /rest/api/3/issue

A name that is not a work type of the project is rejected with 400.

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 .

POST /rest/api/3/issue

No issuetype at all. The 400 is keyed on issuetype and asks to specify one.

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 .

How it behaves

  • Create with {id} answered 201 (ZZREF-9) and create with {name} answered 201 for both Task and Sub-task.
  • Leaving issuetype out answered 400 with errors.issuetype = 'Specify an issue type'; a name outside the project's scheme answered 400 with 'Specify a valid issue type'.
  • GET /rest/api/3/issuetype/{id} answered with the work type object; there is no path that takes a name.

Pitfalls

  • A name can match several entries on a site (Task appears four times in the site list), so the id is the safer key in code that moves between projects.
  • The name is matched inside the project, so the same name may resolve to a different id from project to project.
  • Reading one work type by id needs Browse projects in a project that uses it, or Administer Jira (spec text).

Questions and answers

Should I send issuetype by name or by id?

Both created work items. The id does not depend on language or on duplicate names.

Which error means the work type is not in the project?

errors.issuetype = 'Specify a valid issue type', as in the run with Bug.

Sources

  1. Issue types (Jira REST API v3)
  2. Issues (Jira REST API v3)

Markdown version · All Jira fields pages