Created
March 1, 2018 05:18
-
-
Save lstroud/e8207d12f26e42b85749326618159a13 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
# | |
# List Active Okta Users | |
# | |
import requests | |
import json | |
import pprint | |
import csv | |
token = 'WHATEVER_YOUR_TOKEN_IS' | |
limit = '200' | |
base_url = 'https://mycompany.okta.com/api/v1/' | |
url = base_url + '/users?limit=' + limit | |
headers = {'Authorization' : 'SSWS ' + token, | |
'Accept' : 'application/json', | |
'Content-Type' : 'application/json' } | |
r = requests.get(url, headers=headers) | |
json_obj = r.json() | |
with open('active-users.csv', 'w', newline='') as csvfile: | |
fieldnames = ['firstName', 'lastName', 'login', 'email'] | |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | |
writer.writeheader() | |
for json_row in json_obj: | |
writer.writerow({ | |
'firstName': json_row['profile']['firstName'], | |
'lastName': json_row['profile']['lastName'], | |
'login': json_row['profile']['login'], | |
'email': json_row['profile']['email'] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@lstroud, @YuvrajKukar, this version paginates