Spaces:
Running
Running
import requests | |
# Replace with your actual Cloudflare API token | |
API_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN") | |
# Cloudflare API endpoint for getting account details | |
url = "https://api.cloudflare.com/client/v4/accounts" | |
# Headers for the API request | |
headers = { | |
"Authorization": f"Bearer {API_TOKEN}", | |
"Content-Type": "application/json" | |
} | |
# Making the API request | |
response = requests.get(url, headers=headers) | |
# Checking if the request was successful | |
if response.status_code == 200: | |
# Parsing the JSON response | |
data = response.json() | |
if data['success']: | |
accounts = data['result'] | |
for account in accounts: | |
account_id = account['id'] | |
account_name = account['name'] | |
print(f"Account Name: {account_name}, Account ID: {account_id}") | |
else: | |
print("Error fetching account details:", data['errors']) | |
else: | |
print("Failed to fetch account details. HTTP Status Code:", response.status_code) | |