Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get more than 50 managed users via admin API?

Matías Völgyi
Contributor
July 23, 2024

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"

base_url = f"https://api.atlassian.com/admin/v1/orgs/{orgId}/users"
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? 

2 answers

1 vote
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2024

Hi @Matías Völgyi 

It is not possible to return more than 50 users at a time for that endpoint.  I believe you use the cursor parameter with the returned URL from each call.

Please look here to learn more about the technique:

https://developer.atlassian.com/cloud/admin/organization/rest/api-group-users/#api-v1-orgs-orgid-users-get

https://community.developer.atlassian.com/t/get-list-of-users-from-organization-managed-account/73742

Kind regards,
Bill

0 votes
Oday Rafeh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 23, 2024

Hi @Matías Völgyi , 

Please try to use the limit and start query parameters instead of page.

 

If you need more help to to do that let me know please. 

 

Best regards 

Oday Rafeh

Matías Völgyi
Contributor
July 24, 2024

Still only get the 50 users
Capture.PNG

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events