Created
March 25, 2025 11:20
-
-
Save vikrantyadav11/af3b77c2a5fbecef7e01f1f51ef8c249 to your computer and use it in GitHub Desktop.
Get Users in Atlassian Cloud Instance Along with Last Active Date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import csv | |
# Constants | |
ORG_ID = "YOUR_ORG_ID" | |
BASE_URL = f"https://api.atlassian.com/admin/v1/orgs/{ORG_ID}/users" | |
BEARER_TOKEN = "your_bearer_token_here" # Replace with your actual token | |
HEADERS = { | |
"Authorization": f"Bearer {BEARER_TOKEN}", | |
"Accept": "application/json" | |
} | |
# CSV file name | |
CSV_FILE = "atlassian_users.csv" | |
# Function to fetch users | |
def fetch_users(): | |
users = [] | |
url = BASE_URL | |
while url: | |
response = requests.get(url, headers=HEADERS) | |
if response.status_code != 200: | |
print(f"Error: {response.status_code}, {response.text}") | |
break | |
data = response.json() | |
for user in data.get("data", []): | |
users.append([ | |
user.get("name", "N/A"), | |
user.get("account_id", "N/A"), | |
user.get("email", "N/A"), | |
user.get("access_billable", "N/A"), | |
user.get("account_status", "N/A"), | |
user.get("last_active", "N/A") | |
]) | |
# Check if there is a next page | |
url = data.get("links", {}).get("next", "") | |
return users | |
# Function to write data to CSV | |
def save_to_csv(users): | |
with open(CSV_FILE, mode="w", newline="", encoding="utf-8") as file: | |
writer = csv.writer(file) | |
writer.writerow(["Name", "Account ID", "Email", "Access Billable", "Account Status", "Last Active"]) | |
writer.writerows(users) | |
print(f"Data saved to {CSV_FILE}") | |
if __name__ == "__main__": | |
user_data = fetch_users() | |
if user_data: | |
save_to_csv(user_data) | |
else: | |
print("No user data retrieved.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment