Clear features in AGOL

858
1
09-27-2016 10:13 AM
RaymundoValencia_Martinez
New Contributor II

I need do a python script to delete all features in a feature service from AGOL, someone know how can i do this?

thanks 

0 Kudos
1 Reply
TimothyHales
Esri Notable Contributor

Here is a Python sample that allows you to delete rows from a service:

ArcREST/delete_rows_from_service.py at master · Esri/ArcREST · GitHub 

Stephen Lead‌ also provided the follow example on Github as well:

import urllib, urllib2, json

serviceEndPoint = "http://<server>/ArcGIS/rest/services/<name>/FeatureServer/<ID>/"

#Query the server for the objects to be deleted
params = urllib.urlencode({'where': <whereclause>, 'f': 'json', 'returnIdsOnly': 'true'})
response = urllib2.urlopen(serviceEndPoint + "query?", params).read()

#Convert the response into JSON then extract the IDs. Convert to a string
data = json.loads(response)
IDs = data["objectIds"]
range = ','.join([str(x) for x in IDs])

#Build the delete code, and submit it
delParams = urllib.urlencode({'objectIds': range, 'f': 'json'})
urllib2.urlopen(serviceEndPoint + "deleteFeatures?", delParams)