Unregister All Replicas

07-11-2020 12:13 PM
Status: Open
New Contributor III

ArcGIS Online will not allow you to overwrite an existing hosted feature service if replicas exist.  ArcGIS Online also will not allow you to programatically compile a list of all of the existing replica IDs for a hosted feature service and then use that list to unregister them all.  There needs to be a way to either programatically gather all of the replica IDs and unregister the replicas, or provide an "Unregister All" button on the feature service page so that users do not have to spend hours copying and pasting each individual replica ID into the one-at-a-time "Unregister Replica" tool.

by Anonymous User

There's a function in the ArcGIS API for Python to list all the replicas and unregister them. Just be aware that doing this will break any outstanding offline maps. After removing the replicas, when a user clicks 'Check for update', for their offline map in ArcGIS Explorer/Collector, they will get a sync failed error as the replica can no longer be found.

featureLayerName = "layername"

featureLayer = gis.content.search(query=featureLayerName + " owner:named_user", item_type='Feature Layer Collection', sort_field='relevance', sort_order='desc', max_items=1)

featureDataset = FeatureLayerCollection.fromitem(featureLayer[0])
outstandingReplicas = featureDataset.replicas.get_list()

if outstandingReplicas:
   for replica_dict in outstandingReplicas:
      print("Unregistered replica: {0}".format(replica_dict['replicaID']))
   print("No replicas present")


Hi @Anonymous User, 

It looks like your solution above is what I am looking for. I have gone through the first four lines OK, but I am getting stuck and was hoping for some assistance. 

I get stuck here at this point. I do have USERNAME updated in the actual script

featureLayer = gis.content.search(query= featureLayerName + "owner:USERNAME", item_type='Feature Server', sort_field='relevance', sort_order='desc', max_items=1)

When stepping through, when I hit the print, I return 


Which may be the issue, because then when I continue 

featureDataset = FeatureLayerCollection.fromitem(featureLayer[0])

I receive the error 

Traceback (most recent call last):
File "<string>", line 1, in <module>
IndexError: list index out of range

I've been trying to troubleshoot for a good bit and though I might reach back out to the master for some potential guidance. 


Thanks in advance


by Anonymous User

Hi @mejohnson22,

I haven't been able to check but suspect the problem is with the item type specified as it doesn't look to be valid - Items and item types—ArcGIS REST APIs | ArcGIS Developers

item_type='Feature Server'

I think it's not returning any results from the search, thus it's returning [] & 'list index out of range'.

As an aside - and it doesn't always work - you can enter * into the unRegisterReplica option for a feature service e.g. https://services3.arcgis.com/AkUq3zcWf7TVqyR9/ArcGIS/rest/services/SERVICE_NAME/FeatureServer/unRegisterReplica and that will try and remove all replicas. 


As an aside - and it doesn't always work - you can enter * into the unRegisterReplica option for a feature service e.g. https://services3.arcgis.com/AkUq3zcWf7TVqyR9/ArcGIS/rest/services/SERVICE_NAME/FeatureServer/unRegi... and that will try and remove all replicas. 

This worked for me. Thank you!


Hi @mejohnson22  & @TylerMcGarrity ,

Can you post the specific code for the 2nd option you mentioned to unRegisterReplica?


Hello @LukeGilner1,

No specific code, you just enter an asterisk and click on Unregister Replica:







Awesome!  Thanks for the picture.  Worked for me!