<?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 Unable to update point feature layer in AGOL using Python in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-update-point-feature-layer-in-agol-using/m-p/1620963#M11432</link>
    <description>&lt;P&gt;I am having trouble updating a point feature layer using the most recent API 2.4.1. I have read more posts and blogs and still have not had any luck making this work. What I am trying to do is update a point layer in AGOL using python. This layer is then consumed by other web maps and eventually a dashboard. I've tried the truncate/append process only to successfully truncate the data but have not found the magic line of code that will make the append work. The workflow involves using a CSV file that is updated daily and then pushing that up to AGOL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone shed some light as to what I am doing wrong? I cannot find any detailed information on the new object model for the API that I'd usually use as a roadmap to solve this but the current documentation is quite lacking in examples/details.&lt;/P&gt;&lt;P&gt;Any insights/help would be greatly appreciated. Thanks in advance.&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;import agol_utils&lt;BR /&gt;from arcgis.layers import Service&lt;BR /&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;from arcpy.sa import *&lt;BR /&gt;import arcgis&lt;BR /&gt;from datetime import datetime as dt&lt;BR /&gt;import os, zipfile, glob&lt;BR /&gt;import sys&lt;BR /&gt;import json&lt;BR /&gt;from arcgis.features import FeatureLayer&lt;/P&gt;&lt;P&gt;def TruncateWebLayer(gis=None, target=None):&lt;BR /&gt;try:&lt;BR /&gt;lyr = arcgis.features.FeatureLayer(target, gis)&lt;BR /&gt;lyr.delete_features(where="1=1")&lt;BR /&gt;print ("Successfully truncated layer: " + str(target))&lt;BR /&gt;except:&lt;BR /&gt;print("Failed truncating: " + str(target))&lt;BR /&gt;sys.exit()&lt;/P&gt;&lt;P&gt;def main(location, folder_name, data_source, upload_data_location, raster_names, csv_file_name):&lt;BR /&gt;try:&lt;BR /&gt;#get the current date for file naming etc.&lt;BR /&gt;current_dt = str(int(dt.now().timestamp()))&lt;BR /&gt;#connect with AGOL&lt;BR /&gt;my_gis = agol_utils.connect_to_agol(location)&lt;/P&gt;&lt;P&gt;#make sure I'm logged in and know which version of API I am using&lt;BR /&gt;username = my_gis.users.me.username&lt;BR /&gt;print(username)&lt;BR /&gt;print(arcgis.__version__)&lt;/P&gt;&lt;P&gt;#get the folder the user wants to put the results in on AGOL&lt;BR /&gt;content_manager = arcgis.gis.ContentManager(my_gis)&lt;BR /&gt;folders_obj = my_gis.content.folders #&lt;BR /&gt;item_folder = folders_obj.get(folder=folder_name)&lt;BR /&gt;print(f"Your folder is: {item_folder}")&lt;/P&gt;&lt;P&gt;#AFFES anomalies results point layer item id&lt;BR /&gt;csv_item_id = "5481ace750b0474d804740e28d2d43a2"&lt;BR /&gt;csv_existing_item = my_gis.content.get(csv_item_id)&lt;/P&gt;&lt;P&gt;csv_feature_layer_url = "&lt;A href="https://services1.arcgis.com/TJH5KDher0W13Kgo/arcgis/rest/services/AFFES_Anomaly_Results/FeatureServer/0" target="_blank"&gt;https://services1.arcgis.com/TJH5KDher0W13Kgo/arcgis/rest/services/AFFES_Anomaly_Results/FeatureServer/0&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;csv_feature_layer = FeatureLayer(csv_feature_layer_url)&lt;BR /&gt;update_features = r"C:\TEMP\TESTING\INPUT\aware_testing.gdb\percentile_CoordinateTableToPoint"&lt;BR /&gt;localJSON = r"C:\TEMP\TESTING\INPUT\csvjson.json"&lt;/P&gt;&lt;P&gt;#remove features&lt;BR /&gt;#TruncateWebLayer(my_gis,csv_feature_layer)&lt;BR /&gt;csv_feature_layer.delete_features(where="1=1")&lt;/P&gt;&lt;P&gt;#reference the empty layer as FeatureLayer object from the ArcGIS Python API&lt;BR /&gt;fl = arcgis.features.FeatureLayer(csv_feature_layer, my_gis)&lt;/P&gt;&lt;P&gt;#create a JSON object from the local features&lt;BR /&gt;jSON = arcpy.FeaturesToJSON_conversion(update_features, localJSON)&lt;/P&gt;&lt;P&gt;#create a FeatureSet object from the JSON&lt;BR /&gt;fs = arcgis.features.FeatureSet.from_json(open(localJSON).read())&lt;/P&gt;&lt;P&gt;#add/append the local features to the hosted feature layer.&lt;BR /&gt;fl.edit_features(adds = fs)&lt;/P&gt;&lt;P&gt;print("Feature layer updated")&lt;/P&gt;&lt;P&gt;except arcpy.ExecuteError:&lt;BR /&gt;print(arcpy.GetMessages(2))&lt;BR /&gt;except Exception as e:&lt;BR /&gt;print(f"An error occurred: {e}")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if __name__ == "__main__":&lt;BR /&gt;&lt;BR /&gt;csv_update_file_name = r'percentile.csv'&lt;BR /&gt;input_file_path = os.path.join(r"C:\TEMP\TESTING\INPUT",csv_update_file_name)&lt;BR /&gt;print(input_file_path)&lt;/P&gt;&lt;P&gt;main("home","Situational_Awareness",r"c:\temp\input",r"c:\temp\output","bui_interpolation, dc_interpolation, dmc_interpolation", input_file_path)&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jun 2025 19:18:07 GMT</pubDate>
    <dc:creator>HaroldDoran2</dc:creator>
    <dc:date>2025-06-04T19:18:07Z</dc:date>
    <item>
      <title>Unable to update point feature layer in AGOL using Python</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-update-point-feature-layer-in-agol-using/m-p/1620963#M11432</link>
      <description>&lt;P&gt;I am having trouble updating a point feature layer using the most recent API 2.4.1. I have read more posts and blogs and still have not had any luck making this work. What I am trying to do is update a point layer in AGOL using python. This layer is then consumed by other web maps and eventually a dashboard. I've tried the truncate/append process only to successfully truncate the data but have not found the magic line of code that will make the append work. The workflow involves using a CSV file that is updated daily and then pushing that up to AGOL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone shed some light as to what I am doing wrong? I cannot find any detailed information on the new object model for the API that I'd usually use as a roadmap to solve this but the current documentation is quite lacking in examples/details.&lt;/P&gt;&lt;P&gt;Any insights/help would be greatly appreciated. Thanks in advance.&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;import agol_utils&lt;BR /&gt;from arcgis.layers import Service&lt;BR /&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;from arcpy.sa import *&lt;BR /&gt;import arcgis&lt;BR /&gt;from datetime import datetime as dt&lt;BR /&gt;import os, zipfile, glob&lt;BR /&gt;import sys&lt;BR /&gt;import json&lt;BR /&gt;from arcgis.features import FeatureLayer&lt;/P&gt;&lt;P&gt;def TruncateWebLayer(gis=None, target=None):&lt;BR /&gt;try:&lt;BR /&gt;lyr = arcgis.features.FeatureLayer(target, gis)&lt;BR /&gt;lyr.delete_features(where="1=1")&lt;BR /&gt;print ("Successfully truncated layer: " + str(target))&lt;BR /&gt;except:&lt;BR /&gt;print("Failed truncating: " + str(target))&lt;BR /&gt;sys.exit()&lt;/P&gt;&lt;P&gt;def main(location, folder_name, data_source, upload_data_location, raster_names, csv_file_name):&lt;BR /&gt;try:&lt;BR /&gt;#get the current date for file naming etc.&lt;BR /&gt;current_dt = str(int(dt.now().timestamp()))&lt;BR /&gt;#connect with AGOL&lt;BR /&gt;my_gis = agol_utils.connect_to_agol(location)&lt;/P&gt;&lt;P&gt;#make sure I'm logged in and know which version of API I am using&lt;BR /&gt;username = my_gis.users.me.username&lt;BR /&gt;print(username)&lt;BR /&gt;print(arcgis.__version__)&lt;/P&gt;&lt;P&gt;#get the folder the user wants to put the results in on AGOL&lt;BR /&gt;content_manager = arcgis.gis.ContentManager(my_gis)&lt;BR /&gt;folders_obj = my_gis.content.folders #&lt;BR /&gt;item_folder = folders_obj.get(folder=folder_name)&lt;BR /&gt;print(f"Your folder is: {item_folder}")&lt;/P&gt;&lt;P&gt;#AFFES anomalies results point layer item id&lt;BR /&gt;csv_item_id = "5481ace750b0474d804740e28d2d43a2"&lt;BR /&gt;csv_existing_item = my_gis.content.get(csv_item_id)&lt;/P&gt;&lt;P&gt;csv_feature_layer_url = "&lt;A href="https://services1.arcgis.com/TJH5KDher0W13Kgo/arcgis/rest/services/AFFES_Anomaly_Results/FeatureServer/0" target="_blank"&gt;https://services1.arcgis.com/TJH5KDher0W13Kgo/arcgis/rest/services/AFFES_Anomaly_Results/FeatureServer/0&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;csv_feature_layer = FeatureLayer(csv_feature_layer_url)&lt;BR /&gt;update_features = r"C:\TEMP\TESTING\INPUT\aware_testing.gdb\percentile_CoordinateTableToPoint"&lt;BR /&gt;localJSON = r"C:\TEMP\TESTING\INPUT\csvjson.json"&lt;/P&gt;&lt;P&gt;#remove features&lt;BR /&gt;#TruncateWebLayer(my_gis,csv_feature_layer)&lt;BR /&gt;csv_feature_layer.delete_features(where="1=1")&lt;/P&gt;&lt;P&gt;#reference the empty layer as FeatureLayer object from the ArcGIS Python API&lt;BR /&gt;fl = arcgis.features.FeatureLayer(csv_feature_layer, my_gis)&lt;/P&gt;&lt;P&gt;#create a JSON object from the local features&lt;BR /&gt;jSON = arcpy.FeaturesToJSON_conversion(update_features, localJSON)&lt;/P&gt;&lt;P&gt;#create a FeatureSet object from the JSON&lt;BR /&gt;fs = arcgis.features.FeatureSet.from_json(open(localJSON).read())&lt;/P&gt;&lt;P&gt;#add/append the local features to the hosted feature layer.&lt;BR /&gt;fl.edit_features(adds = fs)&lt;/P&gt;&lt;P&gt;print("Feature layer updated")&lt;/P&gt;&lt;P&gt;except arcpy.ExecuteError:&lt;BR /&gt;print(arcpy.GetMessages(2))&lt;BR /&gt;except Exception as e:&lt;BR /&gt;print(f"An error occurred: {e}")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if __name__ == "__main__":&lt;BR /&gt;&lt;BR /&gt;csv_update_file_name = r'percentile.csv'&lt;BR /&gt;input_file_path = os.path.join(r"C:\TEMP\TESTING\INPUT",csv_update_file_name)&lt;BR /&gt;print(input_file_path)&lt;/P&gt;&lt;P&gt;main("home","Situational_Awareness",r"c:\temp\input",r"c:\temp\output","bui_interpolation, dc_interpolation, dmc_interpolation", input_file_path)&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 19:18:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-update-point-feature-layer-in-agol-using/m-p/1620963#M11432</guid>
      <dc:creator>HaroldDoran2</dc:creator>
      <dc:date>2025-06-04T19:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update point feature layer in AGOL using Python</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-update-point-feature-layer-in-agol-using/m-p/1621789#M11440</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/910284"&gt;@HaroldDoran2&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Plenty of ways to do this as you have probably come across on your research, many hit and miss and dependent of workflows. Here is one that I use from time to time.&lt;/P&gt;&lt;P&gt;Basic overview of workflow...&lt;BR /&gt;- Truncate the FeatureLayer (won't work if sync is set or the layer is an origin in a relationship - you can delete_features instead)&lt;BR /&gt;- Add the CSV as an Item to AGOL&lt;BR /&gt;- Publish CSV as a Service (I do as a table to save on credits)&lt;BR /&gt;- Append tabular data from CSV to FeatureLayer without Geometry&lt;BR /&gt;- Get the Point geometry information from the attributes and apply&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Note: for this workflow the field names in the FeatureLayer always match the field names in the CSV.&lt;/P&gt;&lt;P&gt;Perhaps test on a disposable FeatureLayer and see if it works for your needs?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS, ItemProperties, ItemTypeEnum
from arcgis.features import FeatureLayer, FeatureSet

################################################################################
## ACCESS ARCGIS ONLINE ########################################################

##agol = GIS("home")
agol = GIS("home")

################################################################################
## REQUIRED OBJECTS ############################################################

## get the Feature Layer as a FeatureLayer object
fl_url = "FEATURE_LAYER_URL" # insert the url to the feature layer here

## path to csv file
csv_file = r"C:\path\to\update_agol.csv"

## home folder to add CSV item an table service, these will be deleted
folder = agol.content.folders.get()

## Item properties required when using folder.add()
csv_item_properties = ItemProperties(
    title = "UPLOADED_CSV",
    item_type = ItemTypeEnum.CSV.value
)

## the fields that contain the X and Y values
x_field = "LONGITUDE"
y_field = "LATITUDE"

################################################################################
## TRUNCATE FEATURE LAYER ######################################################

fl = FeatureLayer(
    url = fl_url
)

fl.manager.truncate() # must not be in a relationship or have sync enabled

## OR

## fl.delete_features(where="1=1")

################################################################################
## CSV DATA TO FEATURELAYER: TABLE ONLY - WITHOUT GEOMETRY #####################


## add as csv item in AGOL
csv_agol = folder.add(
    item_properties=csv_item_properties,
    file=csv_file
).result()

## publishing properties so csv is added as a table and not a spatial layer.
## you could publish as a spatial layer and consume credits and then you wouldnt
## have to accomodate for geomtry later on
csv_properties = {
    "type:" : "csv",
    "locationType" : "none"
}

## publish hosted table
csv_ht = csv_agol.publish(publish_parameters=csv_properties)

## use analyze as per append docs when using a csv
csv_data = agol.content.analyze(
    item = csv_agol.id,
    file_type = "csv",
    geocoding_service = None,
    location_type = None
)

## append in data
fl.append(
    item_id = csv_agol.id,
    upload_format = "csv",
    source_info = csv_data,
    upsert = False
)

################################################################################
## UPDATE GEOMETRY #############################################################

## re-get the FeatureLayer object
fl = FeatureLayer(
    url = fl_url
)

## get the current features
fs = fl.query()

## convert FeatureSet object to a dictionary
fs = fs.to_dict()

## add geometry to each feature
for f in fs["features"]:
    f["geometry"] = {"x" : f["attributes"][x_field], "y" : f["attributes"][y_field], "spatialReference" : {"wkid" : 4326, "latestWkid" : 4326}}

## convert dictionary back to a FeatureSet object
fs = FeatureSet.from_dict(fs)

## update the records with the geomtry
fl.edit_features(updates=fs)

################################################################################
## DELETE CSV TEM AND SERVICE ITEM #############################################

csv_agol.delete(permanent=True)
csv_ht.delete(permanent=True)

################################################################################&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 09:58:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-update-point-feature-layer-in-agol-using/m-p/1621789#M11440</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-06-09T09:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update point feature layer in AGOL using Python</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-update-point-feature-layer-in-agol-using/m-p/1621793#M11441</link>
      <description>&lt;P&gt;Thanks Glen I will give that a go and if it works I'll mark it as solved.&lt;/P&gt;&lt;P&gt;cheers&lt;/P&gt;&lt;P&gt;Harold&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 11:42:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-update-point-feature-layer-in-agol-using/m-p/1621793#M11441</guid>
      <dc:creator>HaroldDoran2</dc:creator>
      <dc:date>2025-06-09T11:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update point feature layer in AGOL using Python</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-update-point-feature-layer-in-agol-using/m-p/1621903#M11443</link>
      <description>&lt;P&gt;Hi Glen,&lt;/P&gt;&lt;P&gt;It works...thank you very much for the insight and code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would you expand this to a polygon or line feature class? Thoughts?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Harold&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 17:49:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/unable-to-update-point-feature-layer-in-agol-using/m-p/1621903#M11443</guid>
      <dc:creator>HaroldDoran2</dc:creator>
      <dc:date>2025-06-09T17:49:54Z</dc:date>
    </item>
  </channel>
</rss>

