<?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 Get the Hosted Feature Layers used to create layers in a Hosted Feature Layer View in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-the-hosted-feature-layers-used-to-create/m-p/1488555#M10153</link>
    <description>&lt;P&gt;I have a collection of Hosted Feature Layers Views (Views) that are sourced by layers in a Hosted Feature Layer (HFL).&lt;/P&gt;&lt;P&gt;The collection of Views is ever-changing, we need to know the layer sources for the Views after they are created.&lt;/P&gt;&lt;P&gt;In python code, I would like to examine each layer in each View in order to retrieve its source HFL sublayer.&lt;/P&gt;&lt;P&gt;I can see these values in the ArcGIS Online portal UI. However I have not been able to connect the dots between the layer view and it's source layer in the API.&lt;/P&gt;&lt;P&gt;TIA&lt;/P&gt;</description>
    <pubDate>Mon, 10 Jun 2024 22:24:24 GMT</pubDate>
    <dc:creator>Dirk_Vandervoort</dc:creator>
    <dc:date>2024-06-10T22:24:24Z</dc:date>
    <item>
      <title>Get the Hosted Feature Layers used to create layers in a Hosted Feature Layer View</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-the-hosted-feature-layers-used-to-create/m-p/1488555#M10153</link>
      <description>&lt;P&gt;I have a collection of Hosted Feature Layers Views (Views) that are sourced by layers in a Hosted Feature Layer (HFL).&lt;/P&gt;&lt;P&gt;The collection of Views is ever-changing, we need to know the layer sources for the Views after they are created.&lt;/P&gt;&lt;P&gt;In python code, I would like to examine each layer in each View in order to retrieve its source HFL sublayer.&lt;/P&gt;&lt;P&gt;I can see these values in the ArcGIS Online portal UI. However I have not been able to connect the dots between the layer view and it's source layer in the API.&lt;/P&gt;&lt;P&gt;TIA&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2024 22:24:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-the-hosted-feature-layers-used-to-create/m-p/1488555#M10153</guid>
      <dc:creator>Dirk_Vandervoort</dc:creator>
      <dc:date>2024-06-10T22:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: Get the Hosted Feature Layers used to create layers in a Hosted Feature Layer View</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/get-the-hosted-feature-layers-used-to-create/m-p/1488578#M10154</link>
      <description>&lt;P&gt;If you know what the item ids for your views are you can do it like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
gis = GIS("https://www.arcgis.com", "user", "passwd")

view_id = "425b785aa3564a7d8d71dcc524a8eb9f"
vw_item = gis.content.get(view_id)
relationships = vw_item.related_items(rel_type="Service2Data")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is okay if you only have one relationship. It will give you access to the source item. If the only relatonship is to the source, then you'll get a list of length 1. Simply access that item and get whatever information you need from the Item as usual (id, url, name, etc.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I looked and I didn't see an obvious way to get the FeatureService&amp;nbsp;&lt;EM&gt;sources&lt;/EM&gt; endpoint, but this would be the most direct way to get the info you want. Assuming it actually doesn't exist in the API (someone please let us know if it does), you can get the info like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", "user", "passwd")

# if you already know the direct urls you don't need to do it like this
view_id = "425b785aa3564a7d8d71dcc524a8eb9f"
vw_item = gis.content.get(view_id)

sources_url = f"{vw_item.url}/sources"
data = {"token": gis._con.token, "f": "json"}
r = requests.post(sources_url, data=data)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;r.json() will look something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;{
  "currentVersion" : 11.2, 
  "services" : [
    {
      "name" : "schedule_pnt", 
      "type" : "FeatureServer", 
      "url" : "https://services3.arcgis.com/ON5SbcAnb3abcdef/ArcGIS/rest/services/schedule_pnt/FeatureServer", 
      "serviceItemId" : "9a65d1256fd04370807a60c11988asdfg"
    }
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have a lot to go through, you may need to refresh the token with gis._con.relogin()&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2024 00:02:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/get-the-hosted-feature-layers-used-to-create/m-p/1488578#M10154</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2024-06-11T00:02:08Z</dc:date>
    </item>
  </channel>
</rss>

