Hi there,
I am trying to add a comment via the Jira Cloud REST API that include a codeblock of JSON and keep getting a “400: Error parsing JSON”.
When I test the call JSON in Postman, it works as expected. But when I implement via Python, it throws the error and I cannot figure out why. I have even tested writing the Python JSON to a file and putting that into Postman, which works.
Here is the JSON payload:
{
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": "codeBlock",
"attrs": {
"language": "json"
},
"content": [
{
"type": "text",
"text": "{\n \"result_status_code\": \"204\"\n}"
}
]
}
]
}
}
Here is the test code I am using (note: other calls use the same URL and headers and work):
url = config["jira"]["host"] + "/rest/api/3/issue/" + key + "/comment"
auth = HTTPBasicAuth(config["jira"]["email"], config["jira"]["api_token"])
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
comment = {
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": "codeBlock",
"attrs": {
"language": "json"
},
"content": [
{
"type": "text",
"text": "{\n \"result_status_code\": \"204\"\n}"
}
]
}
]
}
}
print(comment)
print(url)
response = requests.request(
"POST",
url,
data=comment,
headers=headers,
auth=auth
)
Any ideas?
Thanks,
Cam