Select to view content in your preferred language

What is wrong with this code?

131
2
Tuesday
JoseSanchez
Frequent Contributor

Good afternoon,

I am trying to overwrite an AGOL hosted feature class with API Python and testing it from ArcGIS Pro Notebook.

I am able to load the zipped FGDB in AGOL and overwrite the hosted feature class manually.

When I try to do the same thing with my program, selecting the same zipped FGDB, I get the following error message:

<Item title:"MyFGDB_3_gdb" type:Feature Layer Collection owner:xxxxxxxC>
item.type Feature Service
item.url https://services.arcgis.com/8Pc9XBTAsYuxx9Ny/arcgis/rest/services/MyFGDB_3_gdb/FeatureServer
item.title MyFGDB_3_gdb

Overwriting AGOL Hosted Feature Layer... ***************************** ERROR REPORT STARTS Tue 07/28/2026 03:45:40 PM > Error ocurred in: File "C:/Users/e160795/AppData/Local/Temp/ArcGISProTemp29860/xpython_29860/3605199246.py", line 73, in <module> item.publish(overwrite=True, file_type="fileGeodatabase") > Error Class is: <class 'Exception'> > Available error details are: Unable to analyze item. Item type'url' is not supported for anzlyzing, The item needs to be of type file (Error Code: 400) ERROR REPORT ENDS

This is my code:

# prepare signin object to AGOL
print ("Prepare signin object")


# This automatically logs you into the active AGOL/Portal session from ArcGIS Pro
gis = GIS("home")

# Verify your connection by printing your user details
print(f"Successfully logged in as: {gis.users.me.username}")

# publish Local File GEO DB
print ("Publish Local File GEO DB")
# --- Get the item ---
item = gis.content.get(item_id)
print(item)

print(f"item.type {item.type}")
print(f"item.url {item.url}")
print(f"item.title {item.title}")

print("Overwriting AGOL Hosted Feature Layer...")
# Update the item with the new zipped File Geodatabase

item.update(item_properties={}, data=zip_path)

# Publish the new data, overwriting the old service
item.publish(overwrite=True, file_type="fileGeodatabase")

print("Overwrite Completed:")

 

 

 

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

It seems very similar to this

0 Kudos
JoseSanchez
Frequent Contributor

This is what I did and now it works. Instead of trying to overwrite an existing group of hosted feature layers in AGOL, I just uploaded a FGDB and then refreshed individually each hosted feature class  (2 layers and 1 table) ,

See code below:

# --------------------------------------------------------------------
# Upload ZIP using Folder.add()
# --------------------------------------------------------------------

# Root folder
folder = gis.content.folders.get()

#
upload = folder.add(
item_properties={
"title": "TempFGDBUpload",
"type": "File Geodatabase"
},
file=zip_path
)

# Wait for upload to complete
fgdb_item = upload.result()

print(f"Upload complete: {fgdb_item.id}")

# Hosted Feature Layer
item = gis.content.get(item_id)  ##  id of the Hosted feature layer  in AGOL
#
# FCPoint

layer = item.layers[0]
print(f"item: {item }")
print(f"layer: {layer}")
print(f"fgdb_item.id {fgdb_item.id}")

# ----------------------------------------------------------
# Delete all records
# ----------------------------------------------------------

print("Deleting records...")
delete_result = layer.delete_features(where="1=1")
##print(delete_result)

#--------------------------------------------------------
# Append data
# ----------------------------------------------------------
print("Appending features...")
append_result = layer.append(
item_id=fgdb_item.id,
upload_format="filegdb",
source_table_name="FCPoint"
)
print(append_result)

#
#PCTSLine
layer = item.layers[1]
print(f"layer: {layer}")
# ----------------------------------------------------------
# Delete all records
# ----------------------------------------------------------
print("Deleting records...")
delete_result = layer.delete_features(where="1=1")
##print(delete_result)

#--------------------------------------------------------
# Append data
# ----------------------------------------------------------
print("Appending features...")
append_result = layer.append(
item_id=fgdb_item.id,
upload_format="filegdb",
source_table_name="FCLine"
)
print(append_result)
#
#Tbl
table = item.tables[0]
print(f"layer: {table}")
# ----------------------------------------------------------
# Delete all records
# ----------------------------------------------------------
print("Deleting records...")
delete_result = table.delete_features(where="1=1")
##print(delete_result)

#--------------------------------------------------------
# Append data
# ----------------------------------------------------------
print("Appending features...")
append_result = table.append(
item_id=fgdb_item.id,
upload_format="filegdb",
source_table_name="tbl"
)
print(append_result)


# ---------------------------------------------------------------------
# Delete temporary uploaded FGDB from ArcGIS Online
# ---------------------------------------------------------------------
fgdb_item.delete(permanent=True)
print("Deleted temporary File Geodatabase item from ArcGIS Online.")