1

Using python requests session I can connect to JIRA and retrieve issue information ...

session = requests.Session()
headers = {"Authorization": "Basic %s" % bas64_val}
session.post(jira_rest_url, headers=headers)
jira = session.get(jira_srch_issue_url + select_fields)

# select_fields = the fields I want from the issue

Now I'm trying to post a payload via the JIRA API, using a fixed issue url e.g. "https://my_jira_server.com:1234/rest/api/latest/issue/KEY-9876"

Which should be a case of the following, given: https://developer.atlassian.com/jiradev/jira-apis/about-the-jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-edit-issues

payload = { "update": {
    "fixVersions": [ {"set": "release-2.139.0"} ]
}}
posted = session.post(jira_task_url, data=payload)

# returns <Response [405]>
# jira_task_url = https://my_jira_server.com:1234/rest/api/latest/issue/KEY-9876

But this doesn't appear to work! Looking into the http 405 response, suggests that my payload is not properly formatted! Which notably, is the not easiest thing to diagnose.

What am I doing wrong here? Any help on this would be much appreciated.

Please note, I am not looking to use the python jira module, I am using requests.session to manage several sessions for different systems i.e. JIRA, TeamCity, etc..

OneMoreNerd
  • 463
  • 1
  • 6
  • 19

1 Answers1

1

Found the solution! I had two problems:

1) The actual syntax structure should have been:

fix_version = { "update": { "fixVersions": [ {"set" : [{ "name" : "release-2.139.0" }]}]

2) To ensure the payload is actually presented as JSON, use json.dumps() which takes an object and produces a string (see here) AND set 'content-type' to 'application/json':

payload = json.dumps(fix_version)
app_json = { 'content-type': 'application/json' }
session.put(https://.../rest/api/latest/issue/KEY-9876, headers=app_json, data=payload)

Rather than trying to define the JSON manually!

OneMoreNerd
  • 463
  • 1
  • 6
  • 19
  • In the case of the JIRA Server API reference... https://docs.atlassian.com/jira/REST/server/#api/2/issue .. Be sure to note the difference between POST and PUT when performing different actions. – OneMoreNerd Nov 24 '17 at 14:55