gis.users.search()

3443
5
Jump to solution
09-11-2018 03:24 PM
NareshAligeti2
New Contributor II

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

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

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
by Anonymous User
Not applicable

Naresh,

Try 

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

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

NareshAligeti2
New Contributor II

That worked, thanks Atma.

0 Kudos
KateCarlson
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

0 Kudos
KateCarlson
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

0 Kudos
KateCarlson
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)
0 Kudos