<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using Python to identify Map objects used in Esri ArcGIS Enterprise Portal or AGOL Web Applications? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/using-python-to-identify-map-objects-used-in-esri/m-p/1570735#M10985</link>
    <description>&lt;P&gt;I still need to complete the section about pulling data sources for apps; but this code goes through all maps and creates an inventory all layers and adds them to a hosted table (feature layer variable is&amp;nbsp; &lt;EM&gt;warehouse_maps_svc_lyr&lt;/EM&gt;)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Build Map Inventory table - Maps and associated layers

from arcgis.mapping import WebMap
from arcgis.features import FeatureSet
import pandas as pd
wm_items = gis.content.search("*", item_type="Web Map", max_items=500)
print("This ArcGIS Online Organization contains {} web maps.".format(len(wm_items)))

map_count = 0
layer_count =0

for webmap_item in wm_items:
    
    map_count = map_count + 1
    print("---------------------")
    print("Map ",map_count, " of ",len(wm_items))
    ago_map_id = webmap_item.id
    print("Map ID:",ago_map_id)
    map_title = webmap_item.title
    map_owner = webmap_item.owner
    print("Map Title: ",map_title)
    #convert to Map
    wmItem = gis.content.get(ago_map_id)
    webmap = WebMap(wmItem)
    try:
        layers = webmap.layers
        tables = webmap.tables
    except Exception as e:
        print("Error setting layers and tables")

    try:
        # Export Feature Services/Tables
        if len(layers) &amp;gt; 0:
            for layer in layers:
                layer_count = layer_count + 1
                if layer.layerType =="GroupLayer":
                    for g in layer.layers:
                        lyr_url = g.url
                        lyr_id = g.id
                        lyr_name = g.title
                        print("Group Layer Name:",lyr_name)
                        print("Group Layer ID:",lyr_id)
                        print("Group Layer URL:",lyr_url)
                        layer_data = {
                            'ago_map_id': ago_map_id, 
                            'map_title':map_title, 
                            'map_owner':map_owner, 
                            'ago_layer_id': lyr_id,
                            'layer_title':lyr_name,
                            'layer_url':lyr_url}
                        df = pd.DataFrame(layer_data, index=[0])
                        feature_set = FeatureSet.from_dataframe(df)
                        result = warehouse_maps_svc_lyr.edit_features(adds=feature_set)
                else:
                    lyr_url = layer.url
                    lyr_id = layer.id
                    lyr_name = layer.title
                    print("Layer Name:",lyr_name)
                    print("Layer ID:",lyr_id)
                    print("Layer URL:",lyr_url)
                    
                    layer_data = {
                            'ago_map_id': ago_map_id, 
                            'map_title':map_title, 
                            'map_owner':map_owner, 
                            'ago_layer_id': lyr_id,
                            'layer_title':lyr_name,
                            'layer_url':lyr_url}
                    df = pd.DataFrame(layer_data, index=[0])
                    feature_set = FeatureSet.from_dataframe(df)
                    result = warehouse_maps_svc_lyr.edit_features(adds=feature_set)
        if len(tables) &amp;gt; 0 :
            for table in tables:
                print("Table")
                layer_count = layer_count + 1
                lyr_url = table.url
                lyr_id = table.id
                lyr_name = table.title
                print("Table Name:",lyr_name)
                print("Table ID:",lyr_id)
                print("Table URL:",lyr_url)
                
                layer_data = {
                        'ago_map_id': ago_map_id, 
                        'map_title':map_title, 
                        'map_owner':map_owner, 
                        'ago_layer_id': lyr_id,
                        'layer_title':lyr_name,
                        'layer_url':lyr_url}
                df = pd.DataFrame(layer_data, index=[0])
                feature_set = FeatureSet.from_dataframe(df)
                result = warehouse_maps_svc_lyr.edit_features(adds=feature_set)
                
    except Exception as e:
        print("Error getting properties")
print("\t{}\n\t{}".format("Map Count: " + str(map_count), "Layer Count: " + str(layer_count)))   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Dec 2024 20:29:28 GMT</pubDate>
    <dc:creator>usace_sam_rd3</dc:creator>
    <dc:date>2024-12-20T20:29:28Z</dc:date>
    <item>
      <title>Using Python to identify Map objects used in Esri ArcGIS Enterprise Portal or AGOL Web Applications?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/using-python-to-identify-map-objects-used-in-esri/m-p/1481653#M10088</link>
      <description>&lt;P&gt;Hi!&lt;BR /&gt;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?:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;/LI-CODE&gt;&lt;P&gt;Thanks in advance for any suggestions!&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 22:39:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/using-python-to-identify-map-objects-used-in-esri/m-p/1481653#M10088</guid>
      <dc:creator>BBowers_napacounty</dc:creator>
      <dc:date>2024-05-30T22:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to identify Map objects used in Esri ArcGIS Enterprise Portal or AGOL Web Applications?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/using-python-to-identify-map-objects-used-in-esri/m-p/1481662#M10089</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;One way might be to do this:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Scan your portal for webmap items and cache their Item IDs in a set&lt;/LI&gt;&lt;LI&gt;Scan your portal for apps and for each, do the following:&lt;UL&gt;&lt;LI&gt;Get the item's JSON definition using get_data()&lt;/LI&gt;&lt;LI&gt;Use regex to look for any Item IDs in the JSON&lt;/LI&gt;&lt;LI&gt;Anywhere you find an Item ID, check it against your set, and if you get a hit, print it out&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;I can imagine at least two scenarios where I don't think this would work and you'd need some extra logic:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;An app that uses an external organization's webmap&lt;/LI&gt;&lt;LI&gt;Embedded content panels that include a URL but not an Item ID&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 23:18:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/using-python-to-identify-map-objects-used-in-esri/m-p/1481662#M10089</guid>
      <dc:creator>MobiusSnake</dc:creator>
      <dc:date>2024-05-30T23:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to identify Map objects used in Esri ArcGIS Enterprise Portal or AGOL Web Applications?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/using-python-to-identify-map-objects-used-in-esri/m-p/1570735#M10985</link>
      <description>&lt;P&gt;I still need to complete the section about pulling data sources for apps; but this code goes through all maps and creates an inventory all layers and adds them to a hosted table (feature layer variable is&amp;nbsp; &lt;EM&gt;warehouse_maps_svc_lyr&lt;/EM&gt;)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Build Map Inventory table - Maps and associated layers

from arcgis.mapping import WebMap
from arcgis.features import FeatureSet
import pandas as pd
wm_items = gis.content.search("*", item_type="Web Map", max_items=500)
print("This ArcGIS Online Organization contains {} web maps.".format(len(wm_items)))

map_count = 0
layer_count =0

for webmap_item in wm_items:
    
    map_count = map_count + 1
    print("---------------------")
    print("Map ",map_count, " of ",len(wm_items))
    ago_map_id = webmap_item.id
    print("Map ID:",ago_map_id)
    map_title = webmap_item.title
    map_owner = webmap_item.owner
    print("Map Title: ",map_title)
    #convert to Map
    wmItem = gis.content.get(ago_map_id)
    webmap = WebMap(wmItem)
    try:
        layers = webmap.layers
        tables = webmap.tables
    except Exception as e:
        print("Error setting layers and tables")

    try:
        # Export Feature Services/Tables
        if len(layers) &amp;gt; 0:
            for layer in layers:
                layer_count = layer_count + 1
                if layer.layerType =="GroupLayer":
                    for g in layer.layers:
                        lyr_url = g.url
                        lyr_id = g.id
                        lyr_name = g.title
                        print("Group Layer Name:",lyr_name)
                        print("Group Layer ID:",lyr_id)
                        print("Group Layer URL:",lyr_url)
                        layer_data = {
                            'ago_map_id': ago_map_id, 
                            'map_title':map_title, 
                            'map_owner':map_owner, 
                            'ago_layer_id': lyr_id,
                            'layer_title':lyr_name,
                            'layer_url':lyr_url}
                        df = pd.DataFrame(layer_data, index=[0])
                        feature_set = FeatureSet.from_dataframe(df)
                        result = warehouse_maps_svc_lyr.edit_features(adds=feature_set)
                else:
                    lyr_url = layer.url
                    lyr_id = layer.id
                    lyr_name = layer.title
                    print("Layer Name:",lyr_name)
                    print("Layer ID:",lyr_id)
                    print("Layer URL:",lyr_url)
                    
                    layer_data = {
                            'ago_map_id': ago_map_id, 
                            'map_title':map_title, 
                            'map_owner':map_owner, 
                            'ago_layer_id': lyr_id,
                            'layer_title':lyr_name,
                            'layer_url':lyr_url}
                    df = pd.DataFrame(layer_data, index=[0])
                    feature_set = FeatureSet.from_dataframe(df)
                    result = warehouse_maps_svc_lyr.edit_features(adds=feature_set)
        if len(tables) &amp;gt; 0 :
            for table in tables:
                print("Table")
                layer_count = layer_count + 1
                lyr_url = table.url
                lyr_id = table.id
                lyr_name = table.title
                print("Table Name:",lyr_name)
                print("Table ID:",lyr_id)
                print("Table URL:",lyr_url)
                
                layer_data = {
                        'ago_map_id': ago_map_id, 
                        'map_title':map_title, 
                        'map_owner':map_owner, 
                        'ago_layer_id': lyr_id,
                        'layer_title':lyr_name,
                        'layer_url':lyr_url}
                df = pd.DataFrame(layer_data, index=[0])
                feature_set = FeatureSet.from_dataframe(df)
                result = warehouse_maps_svc_lyr.edit_features(adds=feature_set)
                
    except Exception as e:
        print("Error getting properties")
print("\t{}\n\t{}".format("Map Count: " + str(map_count), "Layer Count: " + str(layer_count)))   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2024 20:29:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/using-python-to-identify-map-objects-used-in-esri/m-p/1570735#M10985</guid>
      <dc:creator>usace_sam_rd3</dc:creator>
      <dc:date>2024-12-20T20:29:28Z</dc:date>
    </item>
  </channel>
</rss>

