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,553,214
Community Members
 
Community Events
184
Community Groups

Python API call failed with status 404 and 401 - Confluence Cloud

Hi 

I think I tried all the ressources and helps and just don't find a solution.

Before doing any other thing I want just to check if the combination of User-ID and Token is working correct for the Confluence Cloud. 

The Id I use is from an Admin and the Token shows that it was used and is generated with that admin account. However, the Python program does always fail. 

Does anyone have a good idea what else I could modify ? The code currently looks like this:

 

import requests

BASE_URL = "https://companyname.atlassian.net"
SPACE_URL = f"{BASE_URL}/wiki/spaces/{{space_key}}/overview"
USER_ID = "my.name@companyname.com"
ACCESS_TOKEN = "TokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenTokenToken"
AUTH = f"{USER_ID}:{ACCESS_TOKEN}"
API_URL = f"{BASE_URL}/wiki/rest/api"


def check_api_credentials():
response = requests.get(API_URL, auth=(USER_ID, ACCESS_TOKEN))
if response.status_code == 200:
print("API credentials are valid!")
elif response.status_code == 401:
print("API call failed with status code 401. Check your API credentials.")
else:
print(f"API call failed with status code {response.status_code}")


def list_groups_with_authorizations(space_key):
space_url = SPACE_URL.format(space_key=space_key)
response = requests.get(space_url, headers={"Authorization": f"Basic {AUTH}"})
if response.status_code == 200:
data = response.json()
groups = data["groups"]
print(f"Groups with authorizations in space {space_key}:")
for group in groups:
print(group["name"])
elif response.status_code == 401:
print("API call failed with status code 401. Check your API token and permissions.")
else:
print(f"API call failed with status code {response.status_code}")


check_api_credentials()
list_groups_with_authorizations("OneOfTheSpacesName")

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events