Editing a Hosted Feature Service with Python

Discussion created by fannonj on Nov 6, 2013
Latest reply on Nov 7, 2013 by astauffer-esristaff

I am trying to arrive at a methodology that will allow us to edit features (actually download and then delete) from a hosted feature service in ArcGIS Online using a scheduled python script. After some browsing the forums I see some solutions that use highly customised methods to call the REST api etc. However, what I can looking for is a method that uses arcpy and not lots of custom code.

In ArcGIS 10.1, if I sign in to ArcGIS Online and add the feature service to an ArcMap document, then I can open a cursor (either arcpy.searchcursor or arcpy.da.searchcursor) on a layer in the feature service in the command line window and access the rows (features).

For Example:

featCur = arcpy.SearchCursor(r"myFeatureServiceLayerName")
for feat in featCur:
  print str(feat.getValue("OBJECTID"))

This seems to be close to being the correct solution. However, if I save the layer in the mxd to a layer file and try to open a cursor from outside ArcMap (i.e. in ArcCatalog command line) by using the layer file as input, I get the following error:

ERROR 999999: Error executing function.
Authentication token required.

This occurs whether or not I am signed in to ArcGIS Online.

Has anyone managed to get a similar script working with an online feature service? I cannot be the first person to want to script the download/update of features from a hosted feature service.

Any pointers most appreciated.