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

API Auth gives confusing results (python, request)

Simon König
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 23, 2024

 

 

Hello,

I am currently working on a simple Jira Api Class to use for coming API-Calls.

All I currently want is to create a module I can use to authenticate, check authentication and utilize to make GET, SET,.. and other basic API calls.

I wrote the Authentification Header as was suggested in https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/, but get confusing results.

My auth-header looks like this:

self._auth = HTTPBasicAuth(self._email, self._api_token)
which gives me a <requests.auth.HTTPBasicAuth object at ...>.
To test my connection I am running this request:
response = requests.request(
                "GET",
                url,
                headers=self.header,
                auth= self.auth, timeout=100
                )
given the URL is
url = f"{str(self.base_url)}/rest/api/2/myself".
This function is working and returning a valid request json with my email, accountID and correct baseURL.
So far so good.
To make handling GET request simpler in the future I then proceed to write a funtion that would just make a GET request with given params and my authentification header using:

 

url = f"{self.base_url}/rest/api/latest/{operation}"
        try:
            response = requests.request("GET",url,headers=self.header, params=params, timeout=200)
            response.raise_for_status()
        except requests.exceptions.Timeout as e:
            raise TimeoutError('Timeout Error while using GET Method') from e
Now for my problem:
using url =f"{self.base_url}/rest/api/latest/{operation} with operation = "issue/ISSUE-KEY" I get only a 404 Error.
When checking the URl in a browser I am getting the Issue.json as expected.
Thats why I am thinking it might be an authentication problem.
The User used is site-admin.
In short: I can connect via API call to https://mysite.net/rest/api/2/myself but get a 404 Error on https://mysite.net/rest/api/latest/issue/ISSUEKEY, even though that url is (with the same user) valid to view in browser.
Any help or redirect would be appreciated,
Kind regards

1 answer

1 accepted

2 votes
Answer accepted
Simon König
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 23, 2024

Found the Error.

Seting the Authentification once was not enaugh. I missed to set

auth= self.auth
in my request for my get function.
Nathan Phillips
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 26, 2024

Hey @Simon König,

Thank you for reaching out the Atlassian Community!

Even more, thank you for following up to your own post and providing the resolution, this can be very useful and may help out other Atlassian product users.

Thank you!

Like Simon König likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.

Learn more
AUG Leaders

Upcoming Jira Events