Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Christoph Schaub
Contributor
March 24, 2023

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
Product Admin
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events