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

Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2019

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
Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 29, 2019

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.

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2019

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

0 votes
robert Mugabuhamye
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2019

hello @Amir Katz (Outseer) ,

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

Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2019

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.

robert Mugabuhamye
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2019

@Amir Katz (Outseer) 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.

Amir Katz (Outseer)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 28, 2019

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.

Suggest an answer

Log in or Sign up to answer