How do I make a hosted feature layer editable with the ArcGIS API for Python

2166
4
08-01-2017 10:10 AM
GregMcNamee
New Contributor III

I'm writing a script to upload a FGDB to ArcGIS Online, view it in a web map, and edit it. Using the API for Python. I've figured everything out except how to turn on editing (create, update, delete, etc). Anyone have any idea how to do that?

Any help would be appreciated.

Thanks.

Greg McNamee
0 Kudos
4 Replies
by Anonymous User
Not applicable

To turn on editing, you need to access the published layer as a    FeatureLayerColleciton object in Python and perform an `update_definition()` operation as shown below:

from arcgis.features import FeatureLayerCollection
fortune_fl_item = gis.content.search('title:your_feature_layer', item_type = 'Feature Layer')[0]
flc = FeatureLayerCollection(fortune_fl_item.url, gis)
flc.manager.update_definition({'capabilities':'Create,Delete,Query,Update,Editing,Extract'})

We gave a talk at the UC about this, you can find the notebook here: https://github.com/Esri/arcgis-python-api/blob/master/talks/uc2017/ArcGIS%20Python%20API%20-%20Advan... If you scroll down to the part that talks about 'Editing features' you can find the workflow

GregMcNamee
New Contributor III

Thanks. I had just read it here: Updating feature layer properties | ArcGIS for Developers 

I appreciate the help.

Greg McNamee
0 Kudos
SarthakTewari24
New Contributor

Hi,

When I run the update_definition on my hosted feature layer published using file geodatabase. I get the following error:

 

code - 

flc.manager.update_definition({'capabilities':'Create,Delete,Query,Update,Editing'})

 

SarthakTewari24_0-1640011407323.png

Any ideas on what could be the issue?

 

0 Kudos
ceredajunior_UnB
New Contributor

Same error here, using ArcGIS API for Python 2.1.0.2. 

If you use the code below in a FeatureClass enabled for editing directly in ArcGIS Online (via the user interface), it responds "capabilities": "Create,Delete,Query,Update,Editing", but if you turn off and try fl.manager.update_definition(, same error of @SarthakTewari24  (in <module> fl.manager.update_definition({'capabilities': 'Create,Delete,Query,Update,Editing'}) Exception: Unable to update feature service definition.
Invalid definition for 'Capabilities'.
Invalid definition for System.String
(Error Code: 400). 

props = fl.properties
print(props)
0 Kudos