Jira API throwing 400 error on Python script

Steve Suranie June 22, 2022

I'm trying to update the description field using the API but I keep getting a 400 error. The auth is correct as I can use GET for projects, issues, comments, etc. Here's the function where I make the PUT call: 

def updateTicket(dictData):

strKey = dictData["key"]
dictFields = {"fields": {"description": "test"}}

strURL = "https://kargo1.atlassian.net/rest/api/3/issue/" + strKey

response = requests.put(strURL, json="{'fields': {'description': 'test'}}", headers=myHeader)

print(response.reason)

And the output is: 

Bad Request

I'm not new to programming but fairly new to Python. I did see some other questions in here with similar issues where the culprit was the Requests module. It automatically does a json.dumps() call on json data passed and the OP was already doing that in his code so the JSON was malformed. 

I don't believe that is my issue as  I am hardcoding the JSON string in the request call. 

Any help would be appreciated 

1 answer

0 votes
Tommy Augustine June 22, 2022

Check and make sure its not requiring ADF formatting:

Note that the descriptionenvironment, and any textarea type custom fields (multi-line text fields) take Atlassian Document Format content. Single line custom fields (textfield) accept a string and don't handle Atlassian Document Format content.

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-put

https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/

Steve Suranie June 22, 2022

That seems like a lot of overkill if someone wants to just add some simple text. Be nice if there was an option to choose between some rich text and plain text formatting. 

Tommy Augustine June 22, 2022

I agree!

 

As a quick & dirty troubleshoot, have you tried formatting the payload data according to these Rest Examples in links below? You be able to test with the Curl examples provided if you have a Mac or Linux box:

Create Issue:

https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/

Edit Issues:

https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-edit-issues-6291632/

That's about all I can think of. 

Kargo Tech Comms June 22, 2022

@Tommy Augustine 

The solution worked. I got wrapped up in other stuff and forgot to respond. The formatting requirements is not a huge deal.

Really all I am doing is cleaning up some poorly designed tickets. Someone designed this board and decided it would be a good idea to have a custom field for what is essentially a description and so users sometimes used the description field, sometimes the custom field, sometimes both, sometimes just decided to put stuff in the comments instead. 

Anyway, it worked, thanks for the pointing me in the right direction. Still think there should be a lighter update option.

Like Tommy Augustine likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events