Jira REST API description field

Hello Everyone,

I am unable to find anything on how I can add a JSON in the description field of the REST v3 API.

I want to add this JSON in the description field so I can create an issue:

{
	"date": "2022-07-27T00:03:40.964-04:00",
	"level": "ERROR",
	"message": "Test message",
	"properties": {
		"log4net:HostName": "TEST-SERVER",
		"accountNumber": "1234567890"
	}
}

If I try do add this and run it I get a message saying invalid input.

Obligatory “I’d recommend taking a look at How To Ask A Good Question ❓” as it is likely to help you get an answer more quickly.

This is a bit confusing. Are you trying to add this data to an existing call so that the description field itself includes the JSON? Can you share a link to the REST API documentation that you are referencing?

Can you share more of the code around where you’re making the call?

1 Like

I want to create a new issue based on some data that the app will get.

Here is the link to the API doc that I used:
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post

Here is the Python code that I have. I want to add the JSON to the description field. If I add it in this form I get the error.

import requests
from requests.auth import HTTPBasicAuth
import json

url = "https://your-domain.atlassian.net/rest/api/3/issue"

auth = HTTPBasicAuth("email@example.com", "<api_token>")

headers = {
   "Accept": "application/json",
   "Content-Type": "application/json"
}

payload = json.dumps({
    "fields": {
        "summary": "Creating a test ticket",
        "project": {
            "key": "IP"
            },
        "issuetype": {
            "id": "10009"
            },
        "description": {
            "date": "2022-07-27T00:03:40.964-04:00",
            "level": "ERROR",
            "message": "Test message",
            "properties": {
                "log4net:HostName": "TEST-SERVER",
                "accountNumber": "1234567890"
                }
            },
        },
    })


response = requests.request(
   "POST",
   url,
   data=payload,
   headers=headers,
   auth=auth
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

I have also created the issue manually and this is what I get when I search for the issue using the following API call. This is just a sample of the API response.
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-get

"description": {
            "version": 1,
            "type": "doc",
            "content": [
                {
                    "type": "paragraph",
                    "content": [
                        {
                            "type": "text",
                            "text": "{"
                        },
                        {
                            "type": "hardBreak"
                        },
                        {
                            "type": "text",
                            "text": "\"date\": \"2022-07-27T00:03:40.964-04:00\","
                        },
                        {
                            "type": "hardBreak"
                        },
                        {
                            "type": "text",
                            "text": "\"level\": \"ERROR\","
                        },
                        {
                            "type": "hardBreak"
                        },
                        {
                            "type": "text",
                            "text": "\"message\": \"Test message\","
                        },
                        {
                            "type": "hardBreak"
                        },
                        {
                            "type": "text",
                            "text": "\"properties\": {"
                        },
                        {
                            "type": "hardBreak"
                        },
                        {
                            "type": "text",
                            "text": "\"log4net:HostName\": \"TEST-SERVER\","
                        },
                        {
                            "type": "hardBreak"
                        },
                        {
                            "type": "text",
                            "text": "\"accountNumber\": \"1234567890\""
                        },
                        {
                            "type": "hardBreak"
                        },
                        {
                            "type": "text",
                            "text": "}"
                        },
                        {
                            "type": "hardBreak"
                        },
                        {
                            "type": "text",
                            "text": "}"
                        }
                    ]
                }

I just want to add the JSON directly without the need to write all of this.

Hello @StefanSpiroski

You seem to be confused between structuring the body of a request using JSON, and providing the actual content for the description field, which needs to be in Atlassian Document Format (ADF).

If you read that part of the API documentation, it provides an example that clearly shows you how to format the description field’s content in ADF, structured within the JSON body:

"description": {
      "type": "doc",
      "version": 1,
      "content": [
        {
          "type": "paragraph",
          "content": [
            {
              "text": "Order entry fails when selecting supplier.",
              "type": "text"
            }
          ]
        }
      ]
    },

In summary, you can’t ‘just add’ JSON into a description field.

If you don’t want to convert your content into ADF, you can use the v2 REST API Edit Issue endpoint and provide the description field’s body in wiki markdown format.

Hello @sunnyape

I saw the part of the API that explained the way to do it but was looking for an easier way to add the JSON data without the need to write all of that.

Thanks for making this more clear.