I have put together a bit of code from examples that looks at a service and loops through the list of replicas and then removes them. I can get this to work on the example Service from ESRI but cannot get it to work from my data.
We are federated and are publishing the data from ArcPro and the result is a hosted Feature Layer in AGOL.
Basically what I am doing is using Field Maps to create a few downloadable sections for the filed to download and view. This is what is creating the replicas.
What I want to do is come around once a month or so and programmatically remove the replicas
If you navigate to the service that is commented out you will see a replica link but there are none there.
BUT if you go into this Feature Layer while signed into AGOL you will see there are 3 of them.
I guess my question is what URL do I use to get to my Hosted Feature Layer where I will be able to see the Replicas to unregister them?
# connect to a GIS
import arcgis
from arcgis.gis import GIS
import arcgis.features
import time
gis = GIS() # connect to www.arcgis.com anonymously.
# we will use a public sync enabled feature layer
duration = 1440 # thats minutes in 24 hours
# THIS URL WORKS GREAT
url = 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Sync/WildfireSync/FeatureServer/'
# TRYING TO GET TO THE FEATURE LAYER TO DO THE SAME
#url = 'https://services.arcgis.com/p5v98VHDX9Atv3l7/ArcGIS/rest/services/VDOT_Bridges_and_Culverts_Inspection/FeatureServer'
bridge_layer = arcgis.features.FeatureLayerCollection(url, gis)
replica_list = bridge_layer.replicas.get_list()
print ("There are " + str(len(replica_list)) + " replicas")
replica1 = bridge_layer.replicas.get(replica_list[0]['replicaID'])
time.localtime(replica1['creationDate']/1000) #dividing by 1000 to convert micro seconds to seconds
ten_min_earlier_epoch = time.time() - duration
ten_min_earlier_epoch
removal_list = []
for r in replica_list:
temp_r = bridge_layer.replicas.get(r['replicaID'])
temp_dict = {'replica_id': r['replicaID'],
'creationDate':temp_r['creationDate']/1000}
#check
if temp_dict['creationDate'] < ten_min_earlier_epoch:
removal_list.append(temp_dict)
print(temp_dict)
# REMOVE THE REPLICAS
#for r in removal_list:
# result = bridge_layer.replicas.unregister(r['replica_id'])
# print(result)