Select to view content in your preferred language

Trouble updating feature service capabilities through Python

61
1
yesterday
JarrettBraden
New Contributor

My county is currently setting up a new Enterprise geodatabase. All the data is hosted locally, and then a data store creates the feature and map services in bulk in our Enterprise Portal. I want to use a python script to automatically update service cababilties for all our services since it's time consuming to go through and set capabilites one by one. 

I'm currently using the following script,

from arcgis.gis import GIS 
from arcgis.features import FeatureLayerCollection 
gis = GIS("https://www.arcgis.com", "username", "password" verify_cert = False) 
url = url = "https://your/server/url/FeatureServer" 
flc = FeatureLayerCollection(url, gis=gis) 
update_dict = { "hasStaticData": False, "capabilities": "Query,Create,Update,Delete,Editing,ChangeTracking,Append"} 
flc.manager.update_definition(update_dict)

 I get the following error,

Exception: {'code': 500, 'message': "Service 'name'.'FeatureServer' does not exist in folder 'name'.", 'details': []}

 I've tried following the steps from;

this How To https://support.esri.com/en-us/knowledge-base/how-to-change-the-capabilities-of-a-hosted-feature-ser... 

this thread, https://community.esri.com/t5/python-questions/enable-editing-amp-editor-tracking-via-python-api/td-... 

and the API documentation here https://developers.arcgis.com/python/latest/guide/updating-feature-layer-properties/ 

to no success.  

The service I want to update is in the folder. I can see it on Server Manager and in the ArcGIS REST Services Directory. I'm stumped, any help would be appreciated!

Tags (3)
0 Kudos
1 Reply
TonyAlmeida
MVP Regular Contributor

The error suggests the script can't find your service at the specified location. You're using ArcGIS Online credentials but your services are hosted locally.

Connect to  Enterprise Porta and Verify the connection

 

 

 

from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection

try:
    # Connect to Enterprise Portal
    gis = GIS("https://yourportal.domain.com/portal", "username", "password", verify_cert=False)
    print(f"Connected to: {gis.properties.portalName}")
    print(f"Logged in as: {gis.users.me.username}")
    
    # Update service capabilities
    service_url = "https://yourserver/rest/services/YourService/FeatureServer"
    flc = FeatureLayerCollection(service_url, gis=gis)
    flc.manager.update_definition({
        "hasStaticData": False,
        "capabilities": "Query,Create,Update,Delete,Editing,ChangeTracking,Append"
    })
    print("Service capabilities updated successfully")

except Exception as e:
    print(f"\nError: {str(e)}")
    print("\nTips:")
    print("- Verify the service URL in your REST Services Directory")
    print("- Check if your user has administrator privileges")
    print("- Ensure the service exists in the specified folder")

 

0 Kudos