Select to view content in your preferred language

ArcGIS Online API - filter users by type, python

453
1
09-20-2022 10:09 AM
mpinney
New Contributor

Hi, I’ve currently got a script that does various things based on iterating through ArcGIS Online usernames.

It all works, but times out after a while as the input list of usernames is too large.

In python, I generate a list of usernames that is an input. This is based on group members, with some group member lists being 200+. I want to be able to filter this list down depending on user type e.g just leaving usernames in the list with user type ‘Creator’. Effectively anything not in ‘Viewer’ or ‘Editor’.

I can’t find the correct function to call or python code to write that will take this large list of usernames, then filter depending on this user type. Then append that into a new blank list.

Any assistance or point in the right direction would be great!

Thanks,

Mike

0 Kudos
1 Reply
PeterKnoop
MVP Regular Contributor

This might help:

# Get a list of all of your users (user objects, not just usernames.)
all_users = gis.users.org_search()

# Use list comprehension to reduce the list of users to those that do not
# have a user type of Creator or Viewer.
[u for u in all_users if( u['userLicenseTypeId'] not in ['Creator','Viewer'] )]

# Or, if you just want a list of the users' usernames.
[u['username'] for u in all_users if( u['userLicenseTypeId'] not in ['Creator','Viewer'] )]

 

0 Kudos