Select to view content in your preferred language

How to get all users belonging to my org

2884
3
Jump to solution
06-21-2021 07:02 AM
VishApte
Esri Contributor

Hi all,

I have a simple requirement, to list all users in my AGOL subscription. I have administrator role in my org's AGOL subscription. My org has more than 1000 users and I am using UserManager and advance_search to paginate. Example code below

um = UserManager(self.gis)
current_user = 0
# TODO: find best pattern to list only organizational users
# currently below code is listing every AGOL user
user_search_pattern = "access: org OR access: public OR access: private"
users_searched = um.advanced_search(query=user_search_pattern, start=current_user, max_users=self.MAX_USERS, as_dict=True, return_count=False)
while (len(users_searched['results']) > 0):
     current_user += len(users_searched['results'])
    for user in users_searched['results']: 
        username = user['username']
        user_details = self.get_user_details(username)
        #TODO: Not sure this is correct logic to ascertain if user is a native AGOL org user
        # For now, use this logic
        if 'orgId' in user_details:
            self.org_users[username] = user_details['orgId']
    # get next pageful users
    users_searched = um.advanced_search(query=user_search_pattern,start=current_user, max_users=self.MAX_USERS)

print("Total #{} organisational users found.".format(len(self.org_users)))

The above code is extremely slow. I am struggling to find correct query parameter I should use. I have tried all different combinations, they all either give empty result or lists every AGOL user including those that do not belong to my org. If I go to my AGOL's organization page in browser, I have 1,309 users. Browser's Dev Tools tell me it runs url param "q=(*)" and pagination parameters. How do I get the same result using ArcGIS API for Python script?

Cheers,

Vish   

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor
from arcgis.gis import GIS
import arcgis

gis = GIS('https://www.arcgis.com', '', '')

user_list = gis.users.search(query = '*', max_users = 10000)
print(user_list)

View solution in original post

3 Replies
DavidPike
MVP Frequent Contributor
from arcgis.gis import GIS
import arcgis

gis = GIS('https://www.arcgis.com', '', '')

user_list = gis.users.search(query = '*', max_users = 10000)
print(user_list)
MichaelVolz
Esteemed Contributor

Does this code require a username and password?

Does the user need to be an administrator of the Portal for the script to run?

0 Kudos
VishApte
Esri Contributor

Thanks @DavidPike , simple as that, it is embarrassing for me.

This script is reporting lot of properties and usage pattern for users. I felt need to use UserManager.advanced_search to support pagination. And UserManager.advanced_search(query="*",....) does not yield same result as  UserManager.search(query="*")

VishApte_0-1624328674898.png

Cheers,

Vish

 

0 Kudos