It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Cannot update Jira issue fields via REST API (in Python)

I am using this code:

payload = {'update': { 'summary': [ {'set': 'new summary here'} ] } }

url = 'https://my-jira-server/resr/api/2/issue/CCB-666'

headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
}

requests.put(url, headers=headers, data=payload)

The call fails with error 400 with this message:

"Unexpected character ('u' (code 117)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')"

I've verified that the 'u' it refers to is the start of the 'update' in the payload.

What am I doing wrong here?

 

3 answers

1 accepted

1 vote
Answer accepted

Found the solution!

After re-reading requests() documentation here: https://requests.kennethreitz.org/en/master/user/quickstart/, in the section titled 'More complicated POST requests',

I changed the code to this:

requests.put(url=url, headers=headers, json=payload)

and it worked.

hello @Amir Katz ,

the u before a string in python stands for Unicode. 
You should check on why your python code is considering the payload as Unicode and not utf-8

No it's not. When I changed the key 'update' to 'Xupdate' I got the error on the character 'X'.

So the API is expecting a different JSON structure, but it's unclear what exactly.

@Amir Katz my mistake, I read the quesiton quickly.

have you tried double quotes instead of the single quote?
the JSON format seems correct.

if you still can't find your solution, I usually use the jira-python  module.

Than ks. But this code is in Python, so single- and double-quotes are the same - a string.

Regarding the jira-python module, I'm aware of it, but it is quite complicated to use. I used it in the past on Linux.

I did try to install it, and it failed when it was trying to compile some SSL-related code.

This is on Windows 10...

I guess the latter problem is for another thread.

Hi Amir,

 

Does quoting the whole payload/data object help?

 

E.g.

payload = {'update': { 'summary': [ {'set': 'new summary here'} ] } }

Becomes

payload = '{"update": { "summary": [ {"set": "new summary here"} ] } }'

 

 

I don't really give this a lot of hope but other than that the request looks fine to me so.. My $0.02

 

//Radek

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

303 views 1 3
Join discussion

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