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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,461,870
Community Members
 
Community Events
176
Community Groups

Problems faced with REST API using python requests

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

 

 

 

 

0 comments

Comment

Log in or Sign up to comment