<?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 How to reference AGOL Hosted Feature Layers in arcpy.metadata module? in Metadata, Catalogs, and Search Questions</title>
    <link>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1264767#M23</link>
    <description>&lt;P&gt;We'd really like to build some automation into our management of ArcGIS Online Hosted Feature Service Metadata, but can't figure out the syntax for referring to these services using the arcpy.metadata.Metadata() module. The &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/metadata/metadata-class.htm" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt; suggests that a URI is sufficient, but apparently a URL doesn't qualify:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;desc = arcpy.Describe("https://services.arcgis.com/cJ9YHowT8TU7DUyn/ArcGIS/rest/services/FAC_Superfund_Site_Boundaries_EPA_Public/FeatureServer/0")
print(desc.name)
L0Superfund_Site_Boundaries
print(desc.dataType)
FeatureClass
print(desc.dataElementType)
DEFeatureClass
target_metadata = arcpy.metadata.Metadata("https://services.arcgis.com/cJ9YHowT8TU7DUyn/ArcGIS/rest/services/FAC_Superfund_Site_Boundaries_EPA_Public/FeatureServer/0")
Traceback (most recent call last):
  File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
  File "C:\Users\thultgre\AppData\Local\Programs\ArcGIS\Pro\Resources\ArcPy\arcpy\metadata.py", line 102, in __init__
    self._arc_object = arcgisscripting.metadata.Metadata(uri)
RuntimeError&lt;/LI-CODE&gt;&lt;P&gt;We can edit the metadata for these hosted feature services in ArcGIS Pro and use the import/export tools on the toolbar, but we'd really like to use python to manipulate these records as well. What are we missing? Hopefully it's something straightforward.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2023 00:54:26 GMT</pubDate>
    <dc:creator>TorrinHultgren2</dc:creator>
    <dc:date>2023-03-07T00:54:26Z</dc:date>
    <item>
      <title>How to reference AGOL Hosted Feature Layers in arcpy.metadata module?</title>
      <link>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1264767#M23</link>
      <description>&lt;P&gt;We'd really like to build some automation into our management of ArcGIS Online Hosted Feature Service Metadata, but can't figure out the syntax for referring to these services using the arcpy.metadata.Metadata() module. The &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/metadata/metadata-class.htm" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt; suggests that a URI is sufficient, but apparently a URL doesn't qualify:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;desc = arcpy.Describe("https://services.arcgis.com/cJ9YHowT8TU7DUyn/ArcGIS/rest/services/FAC_Superfund_Site_Boundaries_EPA_Public/FeatureServer/0")
print(desc.name)
L0Superfund_Site_Boundaries
print(desc.dataType)
FeatureClass
print(desc.dataElementType)
DEFeatureClass
target_metadata = arcpy.metadata.Metadata("https://services.arcgis.com/cJ9YHowT8TU7DUyn/ArcGIS/rest/services/FAC_Superfund_Site_Boundaries_EPA_Public/FeatureServer/0")
Traceback (most recent call last):
  File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
  File "C:\Users\thultgre\AppData\Local\Programs\ArcGIS\Pro\Resources\ArcPy\arcpy\metadata.py", line 102, in __init__
    self._arc_object = arcgisscripting.metadata.Metadata(uri)
RuntimeError&lt;/LI-CODE&gt;&lt;P&gt;We can edit the metadata for these hosted feature services in ArcGIS Pro and use the import/export tools on the toolbar, but we'd really like to use python to manipulate these records as well. What are we missing? Hopefully it's something straightforward.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2023 00:54:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1264767#M23</guid>
      <dc:creator>TorrinHultgren2</dc:creator>
      <dc:date>2023-03-07T00:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference AGOL Hosted Feature Layers in arcpy.metadata module?</title>
      <link>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1281077#M24</link>
      <description>&lt;P&gt;I would also like to know how to do this&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 22:19:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1281077#M24</guid>
      <dc:creator>daniel_marincounty</dc:creator>
      <dc:date>2023-04-20T22:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference AGOL Hosted Feature Layers in arcpy.metadata module?</title>
      <link>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1281096#M25</link>
      <description>&lt;P&gt;Spent a while going back and forth on this with Esri Support, and ended up with several workarounds and an enhancement request.&amp;nbsp; The key takeaway is that today the arcpy.metadata module does not support hosted feature services, and the enhancement request is to address that.&lt;/P&gt;&lt;P&gt;Workarounds include:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Rolling your own with python "requests".&lt;/STRONG&gt; This is pretty straightforward... until you want to edit non-public metadata records owned by enterprise accounts.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
# Example URL for top-level feature service
url = "https://services.arcgis.com/cJ9YHowT8TU7DUyn/arcgis/rest/services/FRS_INTERESTS/FeatureServer/info/metadata"
# Example URL for feature service layer
url = "https://services.arcgis.com/cJ9YHowT8TU7DUyn/ArcGIS/rest/services/FRS_INTERESTS/FeatureServer/0/metadata"

# Send an HTTP GET request to fetch the metadata XML
response = requests.get(metadata_url)

if response.status_code == 200:
    metadata_xml = response.text
    print(metadata_xml)
else:
    print(f"Error fetching metadata: {response.status_code}")&lt;/LI-CODE&gt;&lt;P&gt;This code returns the raw ArcGIS Metadata, which is important. If you add format parameters (?format=default&amp;amp;f=xml) to the URLs above, it will run the XML through a stylesheet and while the result might then be standards-compliant, it won't be your original metadata, and may not be recognized by ArcGIS Pro.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Using the ArcGIS API for Python.&lt;/STRONG&gt; This helps with access to non-public content, but doesn't appear to allow the source ArcGIS metadata to be returned for feature service layers, only the top level service metadata.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Example of retrieving Feature Service metadata:
from arcgis.gis import GIS
import arcgis
from arcgis.features import FeatureLayerCollection
from arcpy import metadata as md
import arcpy
gis = GIS('home')
test = "https://services.arcgis.com/cJ9YHowT8TU7DUyn/ArcGIS/rest/services/FRS_INTERESTS/FeatureServer" 
flc = FeatureLayerCollection(test, gis)
flcitem = arcgis.gis.Item(gis,flc.properties["serviceItemId"])
target_md = md.Metadata(flcitem.metadata)
print(target_md.xml)

# Example of retrieving Feature Service Layer metadata 
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcpy import metadata as md
gis = GIS('home')
t = "https://services.arcgis.com/cJ9YHowT8TU7DUyn/ArcGIS/rest/services/FRS_INTERESTS/FeatureServer/0"
fLayer = FeatureLayer(t)
target_md = md.Metadata(fLayer.metadata)
# Note that the metadata is transformed from ArcGIS Metadata into the default output format for your ArcGIS Online Organizatoin
print(target_md.xml)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 20 Apr 2023 22:52:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1281096#M25</guid>
      <dc:creator>TorrinHultgren2</dc:creator>
      <dc:date>2023-04-20T22:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference AGOL Hosted Feature Layers in arcpy.metadata module?</title>
      <link>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1281396#M26</link>
      <description>&lt;P&gt;Thank you so much for sharing (and saving me the trouble of contacting support&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;)&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 17:46:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1281396#M26</guid>
      <dc:creator>daniel_marincounty</dc:creator>
      <dc:date>2023-04-21T17:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference AGOL Hosted Feature Layers in arcpy.metadata module?</title>
      <link>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1293543#M27</link>
      <description>&lt;P&gt;Wanted to add that I tried grabbing a token from the gis object as documented here:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/get-the-token-using-arcgis-python-api/td-p/876344" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-api-for-python-questions/get-the-token-using-arcgis-python-api/td-p/876344&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But the result was "None" when used when used in ArcGIS Pro and the 'home' authentication option:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
gis = GIS('home')
token = gis._con._token
print(token)

None&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also while snooping around with the gis._con object, tried gis._con.get(metadata_url) which is supposed to automatically append any needed token by default. No luck:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;: A general error occurred: 'authInfo'&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2023 17:00:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1293543#M27</guid>
      <dc:creator>TorrinHultgren2</dc:creator>
      <dc:date>2023-05-26T17:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference AGOL Hosted Feature Layers in arcpy.metadata module?</title>
      <link>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1630714#M103</link>
      <description>&lt;P&gt;Do you happen to have a link to the enhancement request? May be helpful for others to vote on it and/or check the status of it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 16:00:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/metadata-catalogs-and-search-questions/how-to-reference-agol-hosted-feature-layers-in/m-p/1630714#M103</guid>
      <dc:creator>ShaunConwayCOL</dc:creator>
      <dc:date>2025-07-07T16:00:31Z</dc:date>
    </item>
  </channel>
</rss>

