<?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: Overwrite a hosted feature layer with new CSV in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1036965#M5734</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/95426"&gt;@PaulMarano&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to share your script?&lt;/P&gt;</description>
    <pubDate>Tue, 16 Mar 2021 01:03:28 GMT</pubDate>
    <dc:creator>MehdiPira1</dc:creator>
    <dc:date>2021-03-16T01:03:28Z</dc:date>
    <item>
      <title>Overwrite a hosted feature layer with new CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1036780#M5727</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I'm new to the esri community and would like to know if there is a way to overwrite the data in a hosted feature layer while retaining the layer definition. The issue I am running into is after I execute the python script to overwrite the existing layer, all of custom layer definitions, such as "drawingInfo", "maxRecordCount", and "typeIdFieldID", are set back to the default.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As a workaround, I attempted to&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;retrieve the layer definition by retrieving the 'properties' of the feature layer and then using 'manager.update_definition' to re-establish the custom definition but when I do that I get 'TypeError: Object of type PropertyMap is not JSON serializable'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 18:39:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1036780#M5727</guid>
      <dc:creator>PaulMarano</dc:creator>
      <dc:date>2021-03-15T18:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite a hosted feature layer with new CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1036965#M5734</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/95426"&gt;@PaulMarano&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to share your script?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 01:03:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1036965#M5734</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2021-03-16T01:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite a hosted feature layer with new CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1037120#M5735</link>
      <description>&lt;P&gt;Yes....below is the code we are currently using the over write the feature layer:&lt;/P&gt;&lt;P&gt;--- Grab the properties of the point layer from the feature layer&lt;/P&gt;&lt;P&gt;gis = GIS("&lt;A href="https://YOUR.arcgis.com&amp;quot;,'USERNAME" target="_blank"&gt;https://YOUR.arcgis.com",'USERNAME&lt;/A&gt;', 'PASSWORD')&lt;BR /&gt;search_results = gis.content.search('title: THE_LAYER_TITLE','Feature Layer')&lt;BR /&gt;item = search_results[0]&lt;BR /&gt;the_point_layer = item.layers[0]&lt;BR /&gt;the_properties = the_point_layer.properties&lt;/P&gt;&lt;P&gt;--- Over write the feature layer&lt;BR /&gt;from arcgis.features.managers import FeatureLayerCollectionManager&lt;BR /&gt;the_flc = FeatureLayerCollectionManager.fromitem(item)&lt;BR /&gt;the_flc.overwrite(THE_CVS_FILE)&lt;/P&gt;&lt;P&gt;--- Attempt to update the Feature Definition with the properties retrieved from the point layer prior to over writing the layer&lt;BR /&gt;the_point_layer.manager.update_definition({'properties': the_properties})&lt;/P&gt;&lt;P&gt;The code above produces the following error message:&lt;/P&gt;&lt;P&gt;'TypeError: Object of type PropertyMap is not JSON serializable'&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 14:05:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1037120#M5735</guid>
      <dc:creator>PaulMarano</dc:creator>
      <dc:date>2021-03-16T14:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite a hosted feature layer with new CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1037450#M5736</link>
      <description>&lt;P&gt;have a try with:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;the_point_layer.manager.update_definition({'properties': &lt;STRONG&gt;json.dumps&lt;/STRONG&gt;( the_properties}))&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 01:43:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1037450#M5736</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-03-17T01:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite a hosted feature layer with new CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1037582#M5738</link>
      <description>&lt;P&gt;Hi Minbin:&lt;/P&gt;&lt;P&gt;I appreciate your time and help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I do this, I get the error:&lt;/P&gt;&lt;P&gt;TypeError: Object of type PropertyMap is not JSON serializable&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 13:25:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1037582#M5738</guid>
      <dc:creator>PaulMarano</dc:creator>
      <dc:date>2021-03-17T13:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: Overwrite a hosted feature layer with new CSV</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1106589#M6733</link>
      <description>&lt;P&gt;It was the same for me.&amp;nbsp; It is getting confused here&amp;nbsp;&lt;SPAN&gt;{'properties': the_properties}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;In the update_definition method it will do a json.dumps trying to encode the dictionary&amp;nbsp;&lt;SPAN&gt;{'properties': the_properties} to JSON.&amp;nbsp; The issue here is that the_properties is already a json_string, based on how it was retrieved, and in a json string you see json values like null, true, &amp;amp; false.&amp;nbsp; So when creating the dict {'properties': the_properties} you are creating a python dictionary with the key set to a json string.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This confuses the process because json.dumps is looking for None, True, &amp;amp; False values instead of null, true, &amp;amp; false when encoding the string. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So, since the_properties is already a json string, what you want to do before calling the update_definition is convert the json string to a python dictionary or list of dictionaries whatever it may be. Get everything in a python format then pass it to the update_definition where it will encode the dictionary to a json string successfully.&amp;nbsp; At least this is what I have to do in a Jupyter Notebook.&amp;nbsp; It looks something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# parsing _field_info creates a python dictionary, 
# where true=True, false=False, &amp;amp; null=None
json_string_to_dict = json.loads(f'{_field_info}')

# Create the update_dict
update_dict = {"fields": json_string_to_dict}

# Update the definition --&amp;gt; the update_definition method uses json.dumps
# to convert the python dictionary to json_string
result = feature_layer.manager.update_definition(update_dict)
print(str(result))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Or in your case:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;json_string_to_dict = json.loads(f'{the_properties}')
dict_update = {"properties": json_string_to_dict}
result = feature_layer.manager.update_definition(dict_update)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 12 Oct 2021 05:04:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwrite-a-hosted-feature-layer-with-new-csv/m-p/1106589#M6733</guid>
      <dc:creator>JustinReynolds</dc:creator>
      <dc:date>2021-10-12T05:04:04Z</dc:date>
    </item>
  </channel>
</rss>

