I'm trying to use the /admin/v1/orgs/{orgId}/users API but it looks like I'm unable to get more than 50 results back, I have way more managed users, I also tried to add some pagination, but is not working, it keeps paginating ad eternum.
import requests
import json
import logging
# Setup basic logging
logging.basicConfig(level=logging.INFO)
orgId = "My_OrgId"
access_token = "My_Token"
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {access_token}"
}
all_users = []
page = 0
has_more = True
while has_more:
url = f"{base_url}?page={page}"
logging.info(f"Fetching page {page}")
try:
response = requests.get(url, headers=headers, timeout=10) # Added a 10-second timeout
if response.status_code == 200:
data = json.loads(response.text)
users = data.get('data', [])
all_users.extend(users)
page += 1
has_more = len(users) > 0
logging.info(f"Fetched {len(users)} users")
else:
logging.error(f"Failed to fetch users, status code: {response.status_code}, response: {response.text}")
break
except requests.exceptions.Timeout:
logging.error("Request timed out")
break
except Exception as e:
logging.error(f"An error occurred: {e}")
break
logging.info(f"Total users fetched: {len(all_users)}")
This is what I tried without luck.
Do anyone can enlighten me on how to properly use this API endpoint please?