Select to view content in your preferred language

How to query all groups in an ArcGIS Online organization using the ArcGIS API for Python

3721
2
Jump to solution
06-13-2018 07:26 AM
AndrewRudin1
Frequent Contributor

I want to get a report of all groups in AGOL and their user count via the ArcGIS API for Python. I cannot figure out how to get the gis.groups.search() function to return all groups.  All the Esri examples have some sort of text filter applied.  The code I'm running from the ArcGIS Pro Python window is below.  At first I tried using the syntax gis.groups.search(), but this returns the error RuntimeError: Unable to perform group search.'q' parameter must be specified.  Then I tried gis.groups.search('*'), which ran without error, but the result is an empty set.

Sample code run from ArcGIS Pro Python window:

from arcgis.gis import GIS

gis = GIS("https://myorg.maps.arcgis.com",clientid='myclientid')

all_groups = gis.groups.search()

for group in all_groups:

   members = group.get_members()

   print(str(len(members)))

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ChadBiggerstaff2
New Contributor

Instead of passing "*" pass "1=1"

View solution in original post

2 Replies
ChadBiggerstaff2
New Contributor

Instead of passing "*" pass "1=1"

AndrewRudin1
Frequent Contributor

Thank you.  That was the ticket!

Here's some new code you can run the Pro python window.  Not pretty at all, but it does print the title and list of users from the group.

from arcgis.gis import GIS
gis = GIS("pro")
all_groups = gis.groups.search('1=1')
for group in all_groups:
   members = group.get_members()
   users_list = members['users']
   users_string = ','.join(users_list)
   print(group.title + '...' + users_string)

0 Kudos