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!
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")
Tony,
I have verified my connection to Enterprise Portal and followed your code example exactly.
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection
try:
# Connect to Enterprise Portal
gis = GIS("https://MyEnterprise/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://MyEnterprise/server/rest/services/FolderName/ServiceName/FeatureServer/"
flc = FeatureLayerCollection(service_url, gis=gis)
print(flc.properties)
flc.manager.update_definition({
"hasStaticData": False,
"capabilities": "Query,Create,Update,Delete,Editing,ChangeTracking,Append"
})
print("Service capabilities updated successfully")
To the same result,
Error: {'code': 500, 'message': "Service 'ServiceName'.'FeatureServer' does not exist in folder 'FolderName'.", 'details': []}
I've tested it with multiple service URL's to the same result. I added in the print(flc.properties) to verify that my connection works and that I can see the properties of my sercive, and it sucessfully lists out all the properties.
The username and password is the account that owns the portal data store used to publish the layers in bulk, and it has the max permissions it can be given in Portal. I've also been able to the following code to verify that all the services I want to update are in the correct folder, and it also returns everything sucessfully.
gis = GIS("https://MyEnterprise/portal", "Username", 'Password', verify_cert=False)
user = gis.users.get("Username")
folder_items = user.items("FolderName",max_items=1000)
for item in folder_items:
print(f"Item Title: {item.title}, Item Type: {item.type}, Item ID: {item.id}, Item URL: {item.url}")
If it is a privileges issue, I'm not sure what needs to be updated.