This Python script fetches deprovisioned users from an Okta organization and exports their email addresses to a CSV file. The script handles pagination to ensure all deprovisioned users are retrieved, even if the data spans multiple pages.
- Python 3.7+
requests
library
You can install the requests
library using pip:
pip install requests
Ensure that you have the following environment variables set up:
OKTA_TOKEN
: The Okta API token for authentication.OKTA_DOMAIN
: Your Okta domain (e.g.,yourcompany.okta.com
).
You can set these environment variables in your terminal before running the script:
export OKTA_TOKEN="your_okta_token"
export OKTA_DOMAIN="your_okta_domain"
-
Save the script:
Save the script to a file named
fetch-deprovisioned-okta-users.py
. -
Run the script:
Execute the script using Python:
python fetch-deprovisioned-okta-users.py
-
Output:
The script will create a CSV file named
deprovisioned_users_emails.csv
in the/tmp/
directory, containing the email addresses of all deprovisioned users.
The script uses Okta's pagination mechanism to retrieve all deprovisioned users. If there are more users than the specified limit (default is 200), the script will continue to fetch the next set of users until all are retrieved.
The script raises an error if any HTTP request fails, ensuring that you are alerted to issues such as invalid API tokens, incorrect domain names, or connectivity issues.
This project is licensed under the MIT License. See the LICENSE file for details.