gis.users.search()

1470
5
Jump to solution
09-11-2018 03:24 PM
Highlighted
New Contributor

Hi,  How could we retrieve just usernames from 

gis.users.search()

list? I am trying to compare users between Azure active directory and built-in users. I just need the usernames but not the entire list comprehension. Thanks 

-Naresh Aligeti

python api portal

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Contributor

Naresh,

Try 

[user.username for user in gis.users.search()]

which should return you a list of usernames instead of User objects.

View solution in original post

5 Replies
Highlighted
Esri Contributor

Naresh,

Try 

[user.username for user in gis.users.search()]

which should return you a list of usernames instead of User objects.

View solution in original post

Highlighted
New Contributor

That worked, thanks Atma.

Reply
0 Kudos
Highlighted
Occasional Contributor

Thanks for the posted thread, this is helping me as well.  I have a question to add to Naresh's question, I am having a hard time finding an example. 

I need a list of user emails from a specific role in our Org.  The added query parameter is not selecting users in the 'UMN Student' role,  all users are returned:

users = gis.users.search(query='role: UMN Student')
[users.email for users in gis.users.search()]

Any tips for a newbie?  Thanks!

Kate

Reply
0 Kudos
Highlighted
Occasional Contributor

I have have a partial answer to my question now, I need to query the roles we have created by using the role ID that Esri designates when created.  Anyone know how to determine the role ID without have to contact Esri support?

Thanks-
Kate

Reply
0 Kudos
Highlighted
Occasional Contributor
Found some local help on this one as well, posted in case anyone else has similar inquiry.  Below code will query roles and IDs for your Org.
roles = gis.users.roles.all()
for role in roles:
    print(role.name, role.role_id)
Reply
0 Kudos