AnsweredAssumed Answered

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

Question asked by Andrew.Rudin@austintexas.gov_austin on Jun 13, 2018

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)))

Outcomes