Automating SentinelOne Account Data Export: A Python Script for SentinelOne Account Names, IDs, and External IDs Data Retrieval
1 min readJan 13, 2025
Why Automate SentinelOne Account Data Export?
When managing SentinelOne accounts, it is crucial to extract and organize account names, IDs, and external IDs. Manually retrieving this data can be cumbersome and prone to errors, especially in environments with many accounts.
How to Use This Script
- Replace placeholders with your API token, console URL, and output directory.
- Run the script in your Python environment.
- Check the output directory for the
S1namewithExternalIdname.csv
file containing account data.
import requests
import pandas as pd
# User Inputs
API_TOKEN = "<YOUR_API_TOKEN_HERE>" # Replace with your SentinelOne API Token
S1_CONSOLE_URL = "<YOUR_SENTINELONE_CONSOLE_URL>" # Replace with your SentinelOne Console URL (e.g., https://yourcompany.sentinelone.net)
# Output location and filename
OUTPUT_LOCATION = r"<YOUR_OUTPUT_LOCATION>" # Replace with the desired output directory (e.g., r"C:\Dummy\Path\To\Output\Folder\\" )
OUTPUT_FILENAME = "S1namewithExternalIdname.csv"
# API Headers
headers = {
"Content-type": "application/json",
"Authorization": f"APIToken {API_TOKEN}"
}
# API Endpoint for Accounts
accounts_url = f"{S1_CONSOLE_URL}/web/api/v2.1/accounts?limit=1000"
# Initialize list to store account details
all_accounts = []
# Fetch initial account details
response = requests.get(accounts_url, headers=headers).json()
accounts_data = response["data"]
next_cursor = response['pagination'].get('nextCursor')
# Collect account details
while accounts_data:
for account in accounts_data:
all_accounts.append([account['name'].lower(), account['id'], account['externalId']])
if next_cursor:
next_url = f"{accounts_url}&cursor={next_cursor}"
response = requests.get(next_url, headers=headers).json()
accounts_data = response["data"]
next_cursor = response['pagination'].get('nextCursor')
else:
break
# Create DataFrame and export to CSV
df = pd.DataFrame(all_accounts)
output_header = ['Account Name', 'Account ID', 'External ID']
df.to_csv(f"{OUTPUT_LOCATION}{OUTPUT_FILENAME}", index=False, header=output_header)
print(f"Generated file can be located at {OUTPUT_LOCATION}")