Created
August 13, 2019 18:59
-
-
Save dismantl/d52595387ca0fd8934871cf740cb72b0 to your computer and use it in GitHub Desktop.
Export active Okta users to CSV file
This file contains 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
#!/bin/bash | |
# Add your Okta API key and domain here: | |
OKTA_API_KEY=xxxxxxxxxxxxxxx | |
OKTA_DOMAIN=mydomain.okta.com | |
OUTPUT_FILE=okta-users.csv | |
# Write CSV headers | |
echo '"userType","department","firstName","lastName","nickName","displayName","email","title","division","postalAddress","streetAddress","city","state","zipCode","primaryPhone","secondEmail","mobilePhone"' \ | |
> $OUTPUT_FILE | |
# Fetch all active Okta users, convert from JSON to CSV, sort | |
curl -s -S -X GET -H "Accept: application/json" \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: SSWS ${OKTA_API_KEY}" \ | |
--data-urlencode "filter=status eq \"ACTIVE\"" \ | |
"https://${OKTA_DOMAIN}/api/v1/users" \ | |
| jq -r '.[].profile|[.userType, .department, .firstName, .lastName, .nickName, .displayName, .email, .title, .division, .postalAddress, .streetAddress, .city, .state, .zipCode, .primaryPhone, .secondEmail, .mobilePhone]|@csv' \ | |
| sort \ | |
>> $OUTPUT_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a version that paginates.
Running curl with the
-i
or--include
option includes the response headers.