Runtime error: item <item_name> already exists

Last Published: May 28, 2020

Error Message

It is possible to overwrite an existing hosted feature layer in a portal using the overwrite() method in ArcGIS API for Python, as shown in the following sample:

from arcgis.gis import GIS
from IPython.display import display

gis = GIS("", "username", "password", verify_cert=False)

item ="feature_name", "Feature Layer")

service_flayer_collection = FeatureLayerCollection.fromitem(item)


However, in some cases, the following error is returned:

Runtime error: item <item name> already exists.


The error may occur if the published layer is associated with a view layer. Refer to Portal for ArcGIS: Create hosted feature layer views for more information. When searching for the feature layer name with the function, more than one result is returned: the feature layer and the view layer. To check for any associated view layers, the parameter set for the function can be called in the script, as shown in the following sample:

item ="featurename", "Feature Layer")

The code returns all available items with the specified name. The following script shows a sample of the result:

[<Item title:"featurename_1" type:Feature Layer Collection owner:User_1>, <Item title:"featurename" type:Feature Layer Collection owner:User_1>]

Solution or Workaround

To counter the issue of the function, and index or array can be added to the function. As view layers are listed first in the search result, an index of '1' must be inserted for the search to select the right hosted feature layer to be overwritten. The following code sample shows how to do so:

from arcgis.gis import GIS
from IPython.display import display

gis = GIS("", "username", "password", verify_cert=False)

#For using index array method
item ="feature_name", "Feature Layer")[1] //Setting the index for the search function

service_flayer_collection = FeatureLayerCollection.fromitem(item)


Another alternative is to use the method by searching for the item ID of the desired feature. The item ID of a feature can be found on the address bar of a browser when the feature is opened in ArcGIS Online as shown in the following image:

The image of an address bar of an opened Hosted Feature Layer

To do so, modify the script as follows:

#For searching using item ID
item ="item_id")

Article ID:000019281

  • ArcGIS API for Python 1 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic