Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

400 Bad Request on Issue Update

Deleted user June 10, 2013
I'm using python to call the Jira REST api and I keep getting 400 Bad Request. Is there anyway to get a more informative error? This is the current code I have: import httplib, urllib, json data = urllib.urlencode({ 'fields': { 'description': 'test', }, }) request = httplib.HTTPSConnection(host) request.putrequest('PUT', baseUrl + 'issue/CP-2290', data) request.putheader('Accept', 'application/json') request.putheader('Content-type', 'application/json') request.putheader('Authorization', encodeUserData) request.endheaders() response = request.getresponse() print response.status, response.reason

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Deleted user June 10, 2013

I figured it out after. Seems I had to encode the body in JSON since I had the content-type as JSON. See below for the working code:

import httplib, json

host = 'serebra.jira.com'
baseUrl = '/rest/api/latest/'
encodeUserData = 'Basic ' + ('username' + ':' + 'password').encode('base64').rstrip()

conn = httplib.HTTPSConnection(host)
headers = {
	'Accept': 'application/json',
	'Content-Type': 'application/json;charset=UTF-8',
	'Authorization': encodeUserData,
}
body = json.dumps({
	'fields': {
		'environment': 'test',
	}
})

conn.request('PUT', baseUrl + 'issue/CP-2290', headers=headers, body=body)
response = conn.getresponse()

print response.status, response.reason
print response.read()

0 votes
Deleted user June 10, 2013

It does. I've tried modifying many different fields as well. I've also tried using the "updates" options. But it's always a 400 Bad Request. Also, I provided a more readable example of the code (seems the editor doesn't work in Safari so I couldn't format anything). So yeah, the GET works fine... it's just I can't update the issue with a PUT.

import httplib, urllib, json

host = 'example.jira.com'
baseUrl = '/rest/api/latest/'
encodeUserData = 'Basic ' + ('username' + ':' + 'password').encode('base64').rstrip()

data = urllib.urlencode({
	'fields': {
		'summary': 'test',
	},
})

request = httplib.HTTPSConnection(host)
request.putrequest('PUT', baseUrl + 'issue/CP-2290', data)
request.putheader('Accept', 'application/json')
request.putheader('Content-type', 'application/json;charset=UTF-8')
request.putheader('Authorization', encodeUserData)
request.endheaders()

response = request.getresponse()
print response.status, response.reason
print response.read()
0 votes
Zul NS _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 10, 2013

Not really using Python. However, does the description field get return when you use GET method for

rest/api/2/issue/CP-2290/editmeta

TAGS
AUG Leaders

Atlassian Community Events