Automatically fetch user accounts ( Google IAM )
STEP 1: Enable APIs
You’ll need access to one of the following APIs:
-
Cloud Identity API (for non-Google Workspace orgs)
-
Admin SDK API (for Google Workspace)
How to Enable:
-
Go to Google Cloud Console
-
Navigate to: APIs & Services > Library
-
Search for:
-
Cloud Identity AP
- Admin SDK API
-
-
Click Enable
STEP 2: Set Up a Service Account
-
In the Cloud Console, go to : IAM & Admin > Service Accounts
-
Click Create Service Account
-
Name it and click Create and Continue
-
Assign roles:
-
For Cloud Identity: Cloud Identity User Read
-
For Admin SDK: Viewer or User Management Admin
-
STEP 3: Create and Download Credentials
-
Go back to your service account.
-
Under the Keys tab, click Add Key > JSON
-
Save the .json file securely — this will be used to authenticate API requests.
STEP 4: Grant Domain-Wide Delegation (if using Admin SDK)
This allows your service account to impersonate an admin.
-
In the Service Account settings, enable “Enable G Suite Domain-wide Delegation”
-
Go to your Google Admin console
-
Add a new client: Security > API Controls > Domain-wide Delegation
-
Client ID: from your service account JSON
-
STEP 5: Fetch User Accounts Pro-grammatically
Use Python and google-auth + google-api-python-client.
STEP 6: Automate the Process
-
Schedule the script to run via:
-
Cloud Scheduler (GCP-native)
-
Cron job (Linux VM)
-
Cloud Functions / Cloud Run (for serverless)
-
STEP 7: Send or Sync Data
Once you fetch users:
-
You can store them in:
-
Elasticsearch
-
No Comments