Select to view content in your preferred language

Using Python to identify Map objects used in Esri ArcGIS Enterprise Portal or AGOL Web Applications?

235
1
a month ago
Labels (1)
BBowers_napacounty
New Contributor II

Hi!
I'm trying to list the feature layers shown in each map from every web application, dashboard, and storymap on my Enterprise Portal. Is there a way to retrieve all the map objects that belong to an app? Something like this, maybe?:

from arcgis.gis import GIS
from arcgis.mapping import WebMap

gis = GIS(url='https://myesriportal.org/portal', username='admin', password='PUT_PASSWORD_HERE')
webapp_items = gis.content.search(query=f"type:Web Mapping Application", max_items=10000)
webapp_items += gis.content.search(query=f"type:Dashboard", max_items=10000)
webapp_items += gis.content.search(query=f"type:StoryMap", max_items=10000)

#print the web app title, web map title, and layer name
for webapp_item in webapp_items:
    for webmap_item in webapp_item.content.webmaps: # Does something like this exist?
        webmap_obj = WebMap(webmap_item)
        for layer in webmap_obj:
            print(webapp_item.title, webmap_item.title, layer.title)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks in advance for any suggestions!

0 Kudos
1 Reply
MobiusSnake
MVP

I don't think there's an easy way to pull a list of webmaps from an app, especially given the numerous types of apps you could be dealing with - EXB, WAB, StoryMaps, Dashboards, etc.

One way might be to do this:

  • Scan your portal for webmap items and cache their Item IDs in a set
  • Scan your portal for apps and for each, do the following:
    • Get the item's JSON definition using get_data()
    • Use regex to look for any Item IDs in the JSON
    • Anywhere you find an Item ID, check it against your set, and if you get a hit, print it out

I've used this approach when looking for layers referenced by webmaps and it worked well, I haven't tried it with the app-webmap scenario.

I can imagine at least two scenarios where I don't think this would work and you'd need some extra logic:

  • An app that uses an external organization's webmap
  • Embedded content panels that include a URL but not an Item ID

Edit to Add - Re-reading your code I noticed you're not just printing out the webmap Item IDs but also the layer IDs, so you'd probably want to cache those details along with the webmap IDs.