ArcGIS API for Python:
Overwriting AGOL Feature Services

Eric Samson | 4.10.2019


The ArcGIS API for Python helps organize and manage AGOL organizations. The API can be especially useful when an organization starts hosting a lot of datasets and several applications that users depend on. If the user base starts demanding more frequent data updates, it becomes easier to manage all of the layers, maps, and applications using the API.

One task that can be very tedious is overwriting and updating feature services. The API enables AGOL administrators to update their rest services in a few lines of python. I decided to take one of my workflows that I had within modelbuilder and translate it into a python script, so that after the data is processed, I could use the arcgis.manager.overwrite function at the end of the python script. This allows me to immediately overwrite a hosted feature service with an updated version of the layer. The example ESRI provides online, is unnecessarily convulated. I decided to write a clear explanation of how to use the overwrite function. I found a lot of users asking for information about the same thing, most of the answers being more complicated than the below solution:

That's about it. The general steps are:

1. Ensure that you are logged in to the correct organization that contains the feature service you want to overwrite.
2. Create a path to the new feature layer that you will use to replace the live version.
3. Search for the feature service using its ID. You can find the layers ID by using its URL string. In order to use the manager.overwrite function, we have to retrieve it as a Feature Layer Collection. We use the [0] at the end of "ID_Points_ONLINE[0]" to specify that we want the first search result.
4. Run the overwrite function as follow:
(the featurelayercollection from the online rest service).manager.overwrite((Path to local new version))

You will lose all of the symbology on the online layer when you run an overwrite. A good way to circumvent this problem is to use the Apply Symbology From Layer Arcpy tool within your python script before the overwrite occurs.

This workflow isn't a solution for every data situation, it all depends on what you are updating, how frequently, and what the feature service's purpose is.


Email me