I am working on an in house automation and want to post issues in Jira.
I am using Python and can correctly call using the GET methods, but keep receiving a 405 status when trying to use the POST method for
"http://{baseurl}/rest/api/2/issue"
(the base URL is set to a variable and has been used to grab issues so it is correct)
The code I have written is below
[baseurl,jira_headers,auth] = Jira_Auth()
print(baseurl,jira_headers,auth)
url = f"http://{baseurl}/rest/api/2/issue"
jira_headers = {"Accept": "application/json", "Content-Type": "application/json"}
summary = "This is a test summary"
need = "This is a test need"
why = "This is a test why"
body={ "fields":
{ "project": {
"key": "XXX" },
"summary": summary,
"description": need,
"acceptancecriteria": why,
"issuetype": {
"name": "Story" }
}
}
bodys = json.dumps(body)
response = R.post(url,headers = jira_headers,auth=auth,data = body)
print(response.status_code)
Community moderators have prevented the ability to post new answers.
405 Method Not Allowed error that you're getting means the server does not accept the HTTP method you use, which is POST in your case. You are using data = body when making the POST request but you must pass the json = bodys correctly. Right now, you're just passing a raw dictionary instead of JSON string. You already created bodys but you did not use it, you're passing data =body.
In my opinion,
removing the line below
bodys = json.dumps(body)
I guess this will work
body = {...} // your body
response = R.post(url, headers=jira_headers, auth=auth, json=body)
I have updated the code and now get a 400 response (I also added the s to "http" in the URL as other posts have suggested)
import requests as R
from requests.auth import HTTPBasicAuth
from jira_auth import Jira_Auth
from Jama_Auth_Headers import Jama_Auth
import json
[baseurl,jira_headers,auth] = Jira_Auth()
print(baseurl,jira_headers,auth)
url = f"https://{baseurl}/rest/api/2/issue" ## added the 's' on 'http'
jira_headers = {"Accept": "application/json",
"Content-Type": "application/json"}
summary = "This is a test summary"
need = "This is a test need"
why = "This is a test why"
body={
"fields": {
"project":
{
"key": "JPR"
},
"summary": summary,
"description": need,
"acceptancecriteria": why,
"issuetype": {
"name": "Story"
}
}
}
response = R.post(url,headers = jira_headers,auth=auth,json = body) #used 'json' and 'body'
print(response.status_code)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This field is invalid in your payload.
"acceptancecriteria": why,
There is no such standard field in Jira. Remove that line and try again please!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.