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

2932
8
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
8 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)
MartinPeak
New Contributor II
  I get this error too. i can update a definition with fl.manager.update_definition({'capabilities': 'Query'}) , but if I add any more capabilities i get the same error.

I'm trying to add these capabilities -

'Create,Delete,Query,Update,Editing,Sync'. which is the exact string that the feature service had before i overwrote the data in it.
EmmaSchultz1
New Contributor III

I am also getting the same error when trying to update the capabilities to include 'Create,Delete,Query,Update,Editing,Sync'

I followed the steps outlined in the following: https://github.com/Esri/arcgis-python-api/blob/master/guide/04-feature-data-and-analysis/updating-fe... 

Cannot figure out why this error keeps popping up. 

Any word on a solution? 

0 Kudos
EmmaSchultz1
New Contributor III

I would like to add that I do not get the error when passing a single parameter into the 'Capabilities' argument. For example: 

This works: 

update_dict2 = {"capabilities": "Query",
"syncEnabled": False}
test_flc.manager.update_definition(update_dict2)

This does not work: 

update_dict3 = {"capabilities": "Create,Delete,Query,Update,Editing",
"syncEnabled": False}
test_flc.manager.update_definition(update_dict3)

0 Kudos
EmmaSchultz1
New Contributor III

I figured out what the issue was with my script. 

Background: I have a script that overwrites a hosted feature layer from a .xlsx file. After overwriting, the edit capabilities switch back to the default where the only enabled capability is "Query". Therefore, setting the capabilities back to include "Create,Delete,Query,Update,Editing" is needed. I kept on getting the following error: 

Exception: Unable to update feature service definition.
Invalid definition for 'Capabilities'.

The solution, is to include the "hasStaticData" property along with the capabilities. When a layer is set to editable, the hasStaticData property sets to false. So after overwriting since this property is then set to true, I needed to include this in my update dictionary to make the layer editable again: 

#Update capabilities along with the hasStatisData parameter set to true
update_dict3 = {"hasStaticData":False,"capabilities": "Create,Delete,Query,Update,Editing"}
test_flc.manager.update_definition(update_dict3)

 

Hope this can help someone out in the future!

0 Kudos