Select to view content in your preferred language

get list of group members but profile name not username

2145
3
Jump to solution
06-11-2020 05:24 PM
PeterMacKenzie2
Frequent Contributor

This python in an AGOL Jupyter notebook returns me a list of usernames in the group as demo'd here: arcgis.gis module — arcgis 1.8.0 documentation .
Is there a smart way to return the users profile name, rather than their username. 

sa_groups = org_gis.groups.search('title:SA')
g = sa_groups[2]
response = g.get_members()
for user in response['users'] :
print(user)

0 Kudos
1 Solution

Accepted Solutions
GeoJosh
Esri Regular Contributor

Peter,

It looks like the get_members() function returns a dictionary that contains three lists: users, admins, and owners. The contents of these lists are strings, so it doesn't look like we can derive the full name of each user as-is. However, using list comprehensions, you can create a list of <User> objects whose username appears in the resulting dictionary from get_members(). From this new list, you can print each user's name using the fullName property. See the code below:

 # Authentication
portalURL = ""
username = ""
password = ""
org_gis = GIS(portalURL, username, password)


# Get a list of groups that have "SA" in the title.
sa_groups = org_gis.groups.search('title:SA')

# Get a list of all users in the portal (max 1000 users).
all_users = org_gis.users.search(max_users=1000)

# Select the third group in the list
g = sa_groups[2]

# Get a dictionary of all users, admins, owners of the group. 
response = g.get_members()

# Create a list of user objects whose usernames appear in the "users" list of the "response" dictionary.
lst = [u for u in all_users if u.username in response["users"]]
# Print the full name of each user in the list.
for user in lst:
    print(user.fullName)

View solution in original post

3 Replies
GeoJosh
Esri Regular Contributor

Peter,

It looks like the get_members() function returns a dictionary that contains three lists: users, admins, and owners. The contents of these lists are strings, so it doesn't look like we can derive the full name of each user as-is. However, using list comprehensions, you can create a list of <User> objects whose username appears in the resulting dictionary from get_members(). From this new list, you can print each user's name using the fullName property. See the code below:

 # Authentication
portalURL = ""
username = ""
password = ""
org_gis = GIS(portalURL, username, password)


# Get a list of groups that have "SA" in the title.
sa_groups = org_gis.groups.search('title:SA')

# Get a list of all users in the portal (max 1000 users).
all_users = org_gis.users.search(max_users=1000)

# Select the third group in the list
g = sa_groups[2]

# Get a dictionary of all users, admins, owners of the group. 
response = g.get_members()

# Create a list of user objects whose usernames appear in the "users" list of the "response" dictionary.
lst = [u for u in all_users if u.username in response["users"]]
# Print the full name of each user in the list.
for user in lst:
    print(user.fullName)
PeterMacKenzie2
Frequent Contributor

of course! thanks Joshua Herman

0 Kudos
PeterMacKenzie2
Frequent Contributor

additionally (and probably obvious to python pro's) , to return these in an email recipient list, you can modify from 

print(user.fullName)

to

to print(str(user.email) + ",")
0 Kudos