Going Stellar

Home/Jira fields reference

Jira Cloud fields and work types

Jira environment field: Atlassian Document in the API

environment is a long text field for the setup in which a problem occurs. In /rest/api/3 it is written and read as an Atlassian Document, which the OpenAPI text lists together with description and multi-line custom fields. The edit metadata describes its schema as a string.

Endpoints

MethodPathWhat it does
PUT/rest/api/3/issue/{issueIdOrKey}Sets fields.environment to an Atlassian Document.
GET/rest/api/3/issue/{issueIdOrKey}Returns the same document.
GET/rest/api/3/issue/{issueIdOrKey}/editmetaLists environment with the set operation.

Examples

PUT /rest/api/3/issue/{issueIdOrKey}

Sets the environment to a one-paragraph document.

curl

curl -X PUT \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "fields": {
    "environment": {
      "type": "doc",
      "version": 1,
      "content": [
        {
          "type": "paragraph",
          "content": [
            {
              "type": "text",
              "text": "macOS"
            }
          ]
        }
      ]
    }
  }
}' \
  'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=environment'

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=environment',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'returnIssue': 'true', 'fields': 'environment'},
    json={'fields': {'environment': {'type': 'doc',
                                     'version': 1,
                                     'content': [{'type': 'paragraph',
                                                  'content': [{'type': 'text',
                                                               'text': 'macOS'}]}]}}},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "key": "ZZREF-6",
 "fields": {
  "environment": {
   "type": "doc",
   "version": 1,
   "content": [
    {
     "type": "paragraph",
     "content": [
      {
       "type": "text",
       "text": "macOS"
      }
     ]
    }
   ]
  }
 }
}

Sent to Atlassian Cloud on .

GET /rest/api/3/issue/{issueIdOrKey}/editmeta

The edit metadata lists environment as an optional string field with one 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": {
  "environment": {
   "required": false,
   "schema": {
    "type": "string",
    "system": "environment"
   },
   "name": "Environment",
   "key": "environment",
   "operations": [
    "set"
   ]
  }
 }
}

Sent to Atlassian Cloud on .

GET /rest/api/3/issue/{issueIdOrKey}

Reads the stored document back 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": {
  "environment": {
   "type": "doc",
   "version": 1,
   "content": [
    {
     "type": "paragraph",
     "content": [
      {
       "type": "text",
       "text": "macOS"
      }
     ]
    }
   ]
  }
 }
}

Sent to Atlassian Cloud on .

PUT /rest/api/3/issue/{issueIdOrKey}

A multi-line custom field has the same rule and refuses a plain string with a message that names the format.

curl

curl -X PUT \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "fields": {
    "customfield_10163": "plain string"
  }
}' \
  'https://your-domain.atlassian.net/rest/api/3/issue/{issueIdOrKey}?returnIssue=true&fields=customfield_10163'

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=customfield_10163',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'returnIssue': 'true', 'fields': 'customfield_10163'},
    json={'fields': {'customfield_10163': 'plain string'}},
)
print(r.status_code, r.text)

Response: HTTP 400

{
 "errorMessages": [],
 "errors": {
  "customfield_10163": "Operation value must be an Atlassian Document (see the Atlassian Document Format)"
 }
}

Sent to Atlassian Cloud on .

GET /rest/api/2/issue/{issueIdOrKey}

Reads environment through /rest/api/2.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'fields=description,environment' \
  'https://your-domain.atlassian.net/rest/api/2/issue/{issueIdOrKey}'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/rest/api/2/issue/{issueIdOrKey}',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'fields': 'description,environment'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "key": "ZZREF-11",
 "fields": {
  "description": null,
  "environment": "macOS 15, Safari"
 }
}

Sent to Atlassian Cloud on .

How it behaves

  • PUT with a doc of type doc, version 1 and one paragraph answered 200 and the same document came back (sys-environment, read-system-fields).
  • The edit metadata lists environment, but the create metadata for the Task type in the test project did not (editmeta-zz, createmeta-zz-task).
  • The schema reads type string, so the wire format has to come from the OpenAPI text and not from that label (editmeta-zz).
  • Through /rest/api/2 the stored document read back as the plain text macOS 15, Safari (sys-environment-again, sys-description-env-v2).

Pitfalls

  • A plain string is not accepted for multi-line fields in v3. The sibling custom field answered 400 with a request to use an Atlassian Document.
  • The field may be on the edit screen without being on the create screen. Check the create metadata before including it in a create call.
  • Read the content with a document walker or request HTML through expand=renderedFields when text is needed.

Questions and answers

Can environment be set when a work item is created?

Only if the field is part of the create metadata for the project and work type. In the test project it was missing there, so a create call should omit it.

What is the minimum valid document?

The run used type doc, version 1 and a content array with one paragraph that holds one text node.

Sources

  1. Issues (Jira REST API v3)
  2. Edit issue (Jira REST API v3)
  3. Create issue (Jira REST API v3)
  4. Get edit issue metadata (Jira REST API v3)

Markdown version · All Jira fields pages