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.