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
Solved! Go to Solution.
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)
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)
Does this code require a username and password?
Does the user need to be an administrator of the Portal for the script to run?
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="*")
Cheers,
Vish