Many times, we need to fetch Atlassian Account Attributes for reporting and data analysis. This article explains how to fetch Atlassian account attributes in bulk using the Atlassian REST API. While the official API endpoint returns information for a single account at a time, the provided Python script allows you to automate the process for multiple accounts efficiently.
This endpoint is extremely helpful for fetching the Organisation attribute value for users, as it is not available in the UI.
The public API used: The User management REST API
Before you begin, ensure you have the following:
Python 3 is installed on your system(for macOS)
Google Chrome browser with an active Atlassian admin session (required for cookie extraction).
The following Python packages:
browser-cookie3
requests
Install the required packages using pip:
pip3 install browser-cookie3
pip3 install requests
Log in to your Atlassian admin Account using Chrome to ensure your session is active.
Gather the Atlassian Account IDs (aaid1
, aaid2
, etc.) for the users whose attributes you want to fetch. To get it faster, you can Export managed accounts
Obtain a valid Atlassian API access token with the necessary permissions to read user profiles.
Copy and paste the following script into a text file and save it as bulk_fetch_accounts.py
import requests
import json
# List of user account IDs
account_ids = ['aaid1', 'aaid2']
# Your access token
access_token = "<access_token>"
# Function to get user profile information
def get_user_profile(account_id):
url = f"https://api.atlassian.com/users/{account_id}/manage/profile"
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {access_token}"
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return json.loads(response.text)
else:
print(f"Failed to retrieve data for account ID {account_id}: {response.status_code}")
return None
# Iterate over each account ID and fetch profile information
for account_id in account_ids:
user_profile = get_user_profile(account_id)
if user_profile:
print(json.dumps(user_profile, sort_keys=True, indent=4, separators=(",", ": ")))
Open your terminal in macOS and execute:
python3 bulk_fetch_accounts.py
To save the output to a text file:
python3 bulk_fetch_accounts.py >> output.txt
Sanjay Verma
1 comment