
PavanD.79568 (Customer) asked a question.

We use cookies to provide the best website experience and to help understand marketing efforts. We may also share data with ad partners to reach potential customers across the web. To learn more, visit our Privacy Policy. Click here for Your Privacy Choices. You may also opt out of this sharing by signaling your preference via GPC, applicable only to the browser signaling the opt-out.
More information
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.
Select All

We use cookies to provide the best website experience and to help understand marketing efforts. We may also share data with ad partners to reach potential customers across the web. To learn more, visit our Privacy Policy. Click here for Your Privacy Choices. You may also opt out of this sharing by signaling your preference via GPC, applicable only to the browser signaling the opt-out.
More information
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.
Select All
I used the Postman Active Users GET from the the collection to get the first 200 users. The export is based on the user Okta id.
Then modified the postman "limit" variable to: [after] and then used the last exported id as the the "value" for that variable and ran it. It gave me the next 200... then adjusted it again for additional pages of data.
Steve Stevens
I have several thousand users. Can the after variable be used in a loop to get all user within the environment?
I'm trying to think of a way to do this with python but I can't come up with a working solution so far.
here is my solution via python:
import requests,getpass,csv
api_token = getpass.getpass("Input API token: ")
oktaDomain = ""
groupID = ""
notInclude = {"example"}
headers = {
'accept': 'application/json',
'content-type': 'application/json',
'authorization' : 'SSWS {}'.format(api_token)
}
url = "https://{}/api/v1/groups/{}/users?limit=200".format(oktaDomain,groupID)
r = requests.get(url,headers=headers)
try:
while r.status_code == 200:
with open('{}.csv'.format(filename), 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow(['email','firstname','lastname','department','division'])
for item in r.json():
if item.get('status') == 'ACTIVE':
item2 = item.get('profile')
if item2.get('lastName') not in notInclude:
writer.writerow([item2.get('login'),item2.get('firstName'),item2.get('lastName'),item2.get ('department'),item2.get('division')])
#loop stuff
lastID=r.json()[-1].get('id')
url = "https://{}/api/v1/groups/{}/users?after={}".format(oktaDomain,groupID,lastID)
r = requests.get(url,headers=headers)
except IndexError as error:
print('end of users in group')
hope this helps.
Please find attached python file.
here is my solution via python:
response = requests.get(url, headers=headers)
links = response.links
url = links['next']['url']
response = requests.get(url, headers=headers)
links = response.links
url = links['next']['url']
response = requests.get(url, headers=headers)
...
Hello, your script is great but the json it creates has an extra null object that contains the actual Json data. I fix it by opening the file and deleting the first open bracket and the last open bracket and a comma... have you fixed this in a later version of the script?
The function returns two lists: 'users' and 'error'. By simply modifying the last line to
> return (users)
you will get the json of only users.
Thanks for the function @yyh9v (yyh9v) !
happy to help.