I'm trying to use the REST API to create a new issue in our JIRA system. I've been following the documentation, but the return I get is always "405: Method not allowed". I'm assuming this is a POST/GET issue resulting from being redirected (I've read that POST requests are usually converted to GET requests when they're redirected by the receiving server). I'm working in Django (Python) so am using urllib2 rather than cURL. Here's my code (`theIssue` variable is JSON, omitted for brevity):
myUrl = 'http://MYSUBDOMAIN.atlassian.net/rest/api/latest/issue'
myRequest = urllib2.Request(myUrl, theIssue)
myAuthString = base64.standard_b64encode('%s:%s' % ('MYUSER', 'MYPASSWORD'))
myRequest.add_header("Authorization", "Basic %s" % myAuthString)
myRequest.add_header("Content-Type", "application/json")
try:
theResponse = urllib2.urlopen(myRequest)
theReturn = simplejson.load(theResponse)
I've played with adding/removing the trailing slash at the end of the URL, but with or without the trailing slash, I always get the 405 error. I'd be really grateful if anyone can point me in the right direction!
EDIT:
As per Renjith's suggestion, I now have:
myRequest = urllib2.Request(myUrl)
myAuthString = base64.standard_b64encode('%s:%s' % ('MYUSER', 'MYPASS'))
myRequest.add_header("Authorization", "Basic %s" % myAuthString)
myRequest.add_header("Content-Type", "application/json")
try:
theResponse = urllib2.urlopen(myRequest, theIssue)
But I am still getting 405: Method Not Allowed.
EDIT 2:
Again, thanks to Renjith, I've added https:// to the URL, and now I get 400: Bad Request.....?
EDIT 3 (and SOLUTION):
Renjith saved my bacon here. The first problem was the lack of 's' (as in https://) in my URL (the OnDemand docs are also missing the 's'). The second part of the problem was the formatting of my JSON in Django. I was using variables which I had forgotten to str(). Also, note that I've successfully used json.dumps in place of urllib.urlencode. Another point: my URL does now have a trailing slash, as per the docs.
So with those two solutions, everything is now working!