<?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 Update existing hosted feature layer with a new shapefile in ArcGIS Enterprise Portal Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/update-existing-hosted-feature-layer-with-a-new/m-p/1298628#M13696</link>
    <description>&lt;P&gt;I am attempting to use &lt;STRONG&gt;ArcGIS API for Python&lt;/STRONG&gt; to overwrite the underlying data of a hosted feature layer with an shapefile. As this layer is used within a Web App and has pre-configured filters, it cannot simply be replaced with a new layer.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;U&gt;Workflow&lt;/U&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;1) Published the service&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# publish shapefile as feature service
gis = GIS("https://anonymous/arcgis/")
zip_path = '\\\\&amp;lt;anonymise&amp;gt;\\GDW_Catalogue_Items_OS.zip'
published_item = gis.content.add(
    item_properties = {
        "type": "Shapefile", 
        "title": parent,
        "description": "printed maps and charts",
        "tags": "GDW, Catalogue, Footprints, Printed Maps, Printed Charts",
        },
    data = zip_path,
    overwrite=True
)
published_layer = published_item.publish()

# share published feature layer with groups
published_layer.share(groups=['3214a47ac81e4c839a044edf7c42e5ab', '3b3f17e9f2b84aeda789e337da033a7f', 'b4856c293ab84eb389ab323979bd253d', '404b73b5e78b49a0863f8a8cb0f1b6ce'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Sometime later, I wanted to update the data using a new Shapefile:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Access hosted feature layer
gis = GIS("https://anonymous/arcgis/")
search_results = gis.content.search('title:GDW_Catalogue_Items_OS AND type:Feature Service')   
feature_layer_item = search_results[0]

# feature collection
from arcgis.features import FeatureLayerCollection
feature_layer_collection = FeatureLayerCollection.fromitem(feature_layer_item)

# call the overwrite() method to update data
zip_path = '\\\\&amp;lt;anonymise&amp;gt;\\GDW_Catalogue_Items_OS.zip'
feature_layer_collection.manager.overwrite(zip_path)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am given the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
In  [96]:
Line 14:    feature_layer_collection.manager.overwrite(zip_path)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\managers.py, in overwrite:
Line 2183:  layer_info = self._gis._con.get(lyr_url_info, {"f": "json"})

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in get:
Line 506:   ignore_error_key=ignore_error_key,

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_response:
Line 625:   self._handle_json_error(data["error"], errorcode)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_json_error:
Line 648:   raise Exception(errormessage)

Exception: Token Required
(Error Code: 499)
---------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;Troubleshooting Steps:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Manually updated hosted feature layer using portal &lt;EM&gt;(Update Data &amp;gt; Overwrite Entire Layer) - &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: 'There was an Error"&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;FONT color="#000000"&gt;. No more information given.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;Manually created a new feature layer on Portal and manually updated using my new shapefile - successful. But does this not work for Step #1?&lt;/LI&gt;&lt;LI&gt;Ensured my role has the necessary permissions&lt;/LI&gt;&lt;LI&gt;Ensured 'enable editing' in Settings was ticked&lt;/LI&gt;&lt;LI&gt;Ensured 'enable sync' was unticked&lt;/LI&gt;&lt;LI&gt;Ensured both shapefile names were identical&lt;/LI&gt;&lt;LI&gt;Ensured both shapefile schemas were identical&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Please would someone help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Jun 2023 16:13:38 GMT</pubDate>
    <dc:creator>TommyTaylorDev</dc:creator>
    <dc:date>2023-06-13T16:13:38Z</dc:date>
    <item>
      <title>Update existing hosted feature layer with a new shapefile</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-portal-questions/update-existing-hosted-feature-layer-with-a-new/m-p/1298628#M13696</link>
      <description>&lt;P&gt;I am attempting to use &lt;STRONG&gt;ArcGIS API for Python&lt;/STRONG&gt; to overwrite the underlying data of a hosted feature layer with an shapefile. As this layer is used within a Web App and has pre-configured filters, it cannot simply be replaced with a new layer.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;U&gt;Workflow&lt;/U&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;1) Published the service&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# publish shapefile as feature service
gis = GIS("https://anonymous/arcgis/")
zip_path = '\\\\&amp;lt;anonymise&amp;gt;\\GDW_Catalogue_Items_OS.zip'
published_item = gis.content.add(
    item_properties = {
        "type": "Shapefile", 
        "title": parent,
        "description": "printed maps and charts",
        "tags": "GDW, Catalogue, Footprints, Printed Maps, Printed Charts",
        },
    data = zip_path,
    overwrite=True
)
published_layer = published_item.publish()

# share published feature layer with groups
published_layer.share(groups=['3214a47ac81e4c839a044edf7c42e5ab', '3b3f17e9f2b84aeda789e337da033a7f', 'b4856c293ab84eb389ab323979bd253d', '404b73b5e78b49a0863f8a8cb0f1b6ce'])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Sometime later, I wanted to update the data using a new Shapefile:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Access hosted feature layer
gis = GIS("https://anonymous/arcgis/")
search_results = gis.content.search('title:GDW_Catalogue_Items_OS AND type:Feature Service')   
feature_layer_item = search_results[0]

# feature collection
from arcgis.features import FeatureLayerCollection
feature_layer_collection = FeatureLayerCollection.fromitem(feature_layer_item)

# call the overwrite() method to update data
zip_path = '\\\\&amp;lt;anonymise&amp;gt;\\GDW_Catalogue_Items_OS.zip'
feature_layer_collection.manager.overwrite(zip_path)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am given the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
In  [96]:
Line 14:    feature_layer_collection.manager.overwrite(zip_path)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\managers.py, in overwrite:
Line 2183:  layer_info = self._gis._con.get(lyr_url_info, {"f": "json"})

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in get:
Line 506:   ignore_error_key=ignore_error_key,

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_response:
Line 625:   self._handle_json_error(data["error"], errorcode)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_json_error:
Line 648:   raise Exception(errormessage)

Exception: Token Required
(Error Code: 499)
---------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;Troubleshooting Steps:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Manually updated hosted feature layer using portal &lt;EM&gt;(Update Data &amp;gt; Overwrite Entire Layer) - &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: 'There was an Error"&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/EM&gt;&lt;FONT color="#000000"&gt;. No more information given.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;Manually created a new feature layer on Portal and manually updated using my new shapefile - successful. But does this not work for Step #1?&lt;/LI&gt;&lt;LI&gt;Ensured my role has the necessary permissions&lt;/LI&gt;&lt;LI&gt;Ensured 'enable editing' in Settings was ticked&lt;/LI&gt;&lt;LI&gt;Ensured 'enable sync' was unticked&lt;/LI&gt;&lt;LI&gt;Ensured both shapefile names were identical&lt;/LI&gt;&lt;LI&gt;Ensured both shapefile schemas were identical&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Please would someone help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 16:13:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-portal-questions/update-existing-hosted-feature-layer-with-a-new/m-p/1298628#M13696</guid>
      <dc:creator>TommyTaylorDev</dc:creator>
      <dc:date>2023-06-13T16:13:38Z</dc:date>
    </item>
  </channel>
</rss>

