<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D50Z00008G7Ul4SAFOkta Classic EngineIntegrationsAnswered2024-07-22T09:15:32.000Z2017-07-20T08:21:35.000Z2020-10-21T05:21:13.000Z
Okta API to get Active user list fetch only 200 records and we need more than 200
We are using API to get Active Users, for our account there are more than 200 active okta users and even if we give limit more than 200 it returns only 200 records. We are using below API

"{{url}}/api/v1/users?filter=status eq "ACTIVE"&limit=400" 

Is there any way to handle this situation where we can get more than 200 records ? 

  • elnsf (elnsf)

    The article provides no direction on how to use the operators in the query. Can you suggest how to use in powershell or python script to retrieve more than the limit?
  • u5p2z (u5p2z)

    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

     

    Expand Post
  • Brandona.77811 (Customer)

    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.

  • CarlosS.83127 (Customer)

    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')

     

     

    Expand Post
  • yyh9v (yyh9v)

    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)

    ...

    Expand Post
    • Unknown file type
      The file is no longer available.
    • ocodp (ocodp)

      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?

      • x2gkx (x2gkx)

        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.

10 of 11
This question is closed.
Loading
Okta API to get Active user list fetch only 200 records and we need more than 200