Get all maps that contain a feature layer - Python API

453
4
Jump to solution
10-07-2020 06:38 AM
TannerArrington
New Contributor III

Is it possible to find all of the maps that contain any one feature layer in ArcGIS Online using the Python API? For example, if there is a feature layer using frequently across the organization, and I want to find out which maps are using that layer.

I see some documentation about finding relationships between items here. The Map2Service seems to work in one direction - find the services in the map. But is there a way to do this the other direction? 

1 Solution

Accepted Solutions
JoshuaSharp-Heward
Occasional Contributor

Hi Tanner,

I wrote a script to do this last year: gis-administration/search_webmaps_for_services.py at master · joshsharpheward/gis-administration · G... which I designed to be run from ArcGIS Pro, you can download the gp toolbox in that repo to use it straight away! Otherwise if you want to run it from another environment you can copy the code from the script and just modify the 'gis = GIS("pro")' and 'services = arcpy.GetParameter(0)' lines. Note my script also scans web applications in your portal/agol to see if the service is being used in any configured searches, but this can be stripped out easily.

View solution in original post

4 Replies
MehdiPira1
Esri Contributor

Hi Tanner Arrington‌,

You can use reverse direction in related items method to get the web maps in which a feature layer is being used, however, you need to establish a relationship using (add_relationship) with the web maps first.

webmap1 = gis.content.get('webmap ID')
webmap_related_item = gis.content.get('Feature Layer ID')

webmap1.add_relationship(rel_item= webmap_related_item, rel_type= 'Map2Service')
webmap_related_item.related_items('Map2Service', 'reverse')‍‍‍‍‍‍

and conversely, forward direction provides the feature layers (collections) used in the web map.

I hope that helps.

JoshuaSharp-Heward
Occasional Contributor

Hi Tanner,

I wrote a script to do this last year: gis-administration/search_webmaps_for_services.py at master · joshsharpheward/gis-administration · G... which I designed to be run from ArcGIS Pro, you can download the gp toolbox in that repo to use it straight away! Otherwise if you want to run it from another environment you can copy the code from the script and just modify the 'gis = GIS("pro")' and 'services = arcpy.GetParameter(0)' lines. Note my script also scans web applications in your portal/agol to see if the service is being used in any configured searches, but this can be stripped out easily.

View solution in original post

TannerArrington
New Contributor III

Super helpful, thanks a bunch for sharing! 

0 Kudos
JoshuaSharp-Heward
Occasional Contributor

Thanks Tanner, glad I could help out! 

0 Kudos