Python: Error creating Issue: {"errorMessages":["Invalid request. Could not parse request body."]}

Reinaldo G. June 17, 2022

Hi everybody,

Just starting this journey with Jira and struggling when I try to create an issue through a Python code. The error I get from the API as follows:

 

{"errorMessages":["Invalid request. Could not parse request body."]}

 

Does anybody know why this happen and how to fix it?

Here is my code:

 jiraurl = "https://domain.atlassian.net/rest/api/3/issue"
jiraheaders = {

    'Content-Type': 'application/json',

    }
jj= json.dumps({
"fields": 

        {

        "project":{
"key": "MY_KEY"
                 },
        "summary": "My first issue created",
        "description": "My issue description",
        "issuetype": {
                    "name": "Incident"
                    }
          }
        })
response = requests.post('https://domain.atlassian.net/rest/api/3/issue', headers=jiraheaders, json=jj, auth=('email', 'token))

Now, if I try run the same command over cURL, it works perfectly:

curl -D- -u email@token -X POST --header 'Content-Type: application/json' --data '{"fields":{"project":{"key": "MY_KEY"},"summary": "My first issue created","description":"My issue description","issuetype":{"name":"Incident"}}}'

https://domain.atlassian.net/rest/api/2/issue
HTTP/1.1 201 Created
Date: Fri, 17 Jun 2022 16:25:48 GMT
Content-Type: application/json;charset=UTF-8
Server: globaledge-envoy
Timing-Allow-Origin: *
X-Arequestid: request_ID
Set-Cookie: atlassian.xsrf.token=cookie; path=/; SameSite=None; Secure
X-Aaccountid: Account_ID
Cache-Control: no-cache, no-store, no-transform
Vary: Accept-Encoding
X-Envoy-Upstream-Service-Time: 960
Expect-Ct: report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/atlassian-proxy", max-age=86400
Strict-Transport-Security: max-age=63072000; preload
X-Content-Type-Options: nosniff
X-Xss-Protection: 1; mode=block
Atl-Traceid: 56493e3118d37b45
Report-To: {"group": "endpoint-1", "max_age": 600, "endpoints": [{"url": "https://subdomain.cloudfront.net"}], "include_subdomains": true}
Nel: {"report_to": "endpoint-1", "max_age": 600, "include_subdomains": true, "failure_fraction": 0.001}
Transfer-Encoding: chunked

{"id":"343709","key":"MY_KEY-7","self":"https://domain.atlassian.net/rest/api/2/issue/343709"

1 answer

1 accepted

0 votes
Answer accepted
Reinaldo G. June 17, 2022

I just resolved the issue.

 

(1) It's not json=jj 

response = requests.post('https://domain.atlassian.net/rest/api/3/issue', headers=jiraheaders, json=jj, auth=('email', 'token))

It must be data = jj

(2) Description must meet Atlassian Document requirements:

description": {

          "type": "doc",

          "version": 1,

          "content": [

            {

              "type": "paragraph",

              "content": [

                {

                  "type": "text",

                  "text": "description"

                }

              ]

            }

          ]

        },

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events