As I have seen on multiple websites and documentation, each one describes a little different method to use the JIRA API. Some use the JIRA module, some use directly request modules.
First I have explained the way I was able to create issues using session:
(1) By following the documentation, I was able to use CURL command to create a session, then storing JSESSIONID and atlassian.xsrf.token to a text file.(using curl -c cookie.txt -X POST -d {credentianls_json} -h {headers} https://XYZ.com/auth/1/session)
*notice the endpoint is without the keyword /rest/ as opposed to the documentation.
*when /rest/auth/1/session was used no JSESSIONID was generated, only xsrf token
(2) Then I was able to use this cookie.txt to create a issue. (using curl -b cookie.txt -X POST -d {data_fields} -h {headers} https://XYZ.com/rest/api/latest/issue )
data_fields = {with all fields and projectkey in json format}
##ISSUE CREATED##
Now when I try to do the same thing with python requests.
------------trying to do the exact same steps------------------
class JiraEverything(object):
def __init__(self, **kwargs):
if(len(kwargs)!=2):
raise JiraException('In order to use this class atleast provide 2 input')
else:
if 'username' in kwargs.keys():
if 'password' in kwargs.keys():
self.__username = kwargs['username']
self.__password = kwargs['password']
else:
raise JiraException('No password found')
else:
raise JiraException('No username found')
####
def getcookie(self):
headers = {
'Content-Type' : "application/json"
}
params = {
'username': self.__username,
'password': self.__password
}
try:
r = requests.post('https://homework101.atlassian.net/auth/1/session',headers = headers, params = params)
except:
raise JiraException('Could not connect to API, verify your username and password')
#####able to get CookieJar with JSESSIONID and xsrf
###trying to use this to generate new issue
new_headers = {
'Content-Type' : "application/json",
'Set-Cookie' : r.headers['Set-Cookie']
}
data = {with all fields and projectkey in json format}
rr = requests.post('https://homework101.atlassian.net/rest/api/latest/issue', headers = new_headers, data = data)
###########I get 400 error
I have tried with multiple endpoint like createmeta but this url works with curl command. I am not able to find any solution to this problem. If anyone has any idea what is going on. Please provide your input. Thanks
Recommended Learning For You
Level up your skills with Atlassian learning
Learning Path
Become an effective Jira admin
Manage global settings and shared configurations called schemes to achieve goals more quickly.
Streamline Jira administration with effective governance
Improve how you administer and maintain Jira and minimize clutter for users and administrators.
Learning Path
Become an effective Jira software project admin
Set up software projects and configure tools and agile boards to meet your team's needs.