Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,295,866
Community Members
 
Community Events
165
Community Groups

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

Edited

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

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
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,492 views 37 44
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you