We are running ArcGIS Enterprise 10.8.1. I followed this doc here to bulk publish around 50 feature services: Publish layers in bulk from a user-managed data store—Portal for ArcGIS | Documentation for ArcGIS Enterprise
As the doc states, editing is not enabled by default. Is there a way (either through Portal/Server Manager or using Python) to go into the service properties and enable editing?
I'm a little confused on what to put in the JSON file. Say I just want to have just the Query capability on the Feature service, how do I do that?
There is an "extensions" array which contains an object with a typeName == "FeatureServer". One of the object's properties is capabilities. You can add in the "Query" string to enable the capability. The structure looks something like the below:
{"extentions": [ ... ,{ "typeName": "FeatureServer", "capabilities": "Query", "enabled": "true", "maxUploadFileSize": 0, "allowedUploadFileTypes": "", "properties": {...}} ... ] }
In the JSON file, do I just copy the entire map service's JSON ( from sever manager) and edit the Feature Service capabilities section?
Yes, I believe so. The JSON file should be an updated copy of the service properties found at the edit service url. Be sure to leave a copy of the original if you want to revert your changes.
It might also be a good idea to create a service which has Query/Edit capability enabled and see the differences before posting the changes. The ESRI admin enterprise notes are detailed but are human readable.
Also note, I may have been incorrect with the payload variable. If the server returns a parameter-like error (i am guessing), try using json.dumps for the service parameter.
payload = {'f': 'json', 'service':json.dumps(service_json), 'token':token}
This seems to still be an issue in 2025, you can't use the ArcGIS python API to modify referenced feature services, or at least I couldn't get it working.
Here some code I wrote to use the ArcGIS Server admin rest endpoint instead. It updates the capability of all feature services in a folder to add Extract to the default Query capability. Hope it helps someone.
from arcgis import GIS import requests import json domain = 'gis.domain.org' folder = 'MyServerFolder' # login to GIS gis = GIS(url="https://gis.domain.org/portal/home", profile='sangis_portal_aiteadmin') token = gis._con.token # Get a list of services from ArcGIS Server # from a specific folder gis_servers = gis.admin.servers.list() print(gis_servers) # Assuming a single server for simplicity server1 = gis_servers[0] damoa_services = server1.services.list(folder=folder) for service in damoa_services: # Get the service definition service_def = requests.get(f'{service.url}?f=json&token={token}').json() service_name = service_def['serviceName'] # Loop through the service extensions to find the FeatureServer extension i=0 for ect in service_def['extensions']: if ect['typeName'] == 'FeatureServer': print("Enabling Feature Access capabilities...") print(f"original capabilities: {service_def['extensions'][i]['capabilities']}") # Update capabilities by editing the service definition service_def['extensions'][i]['capabilities'] = "Query,Extract" print(f"Updated capabilities: {service_def['extensions'][i]['capabilities']}") # Construct the URL for editing the service definition # This URL is specific to ArcGIS Server REST API edit_service_url = f"https://{domain}/arcgis/admin/services/{folder}/{service_name}.MapServer/edit" try: payload = { 'f': 'json', 'service':json.dumps(service_def), 'token':token } # Make the POST request to update the service definition response = requests.post(url=edit_service_url, data=payload) # Check if the request was successful # This doesn't work, 200 is returned even if the update fails # Check the responce conteent instead if response.status_code == 200: print("Capabilities updated successfully.") else: print(f"Failed to update capabilities: {response.text}") except requests.exceptions.RequestException as e: raise e i=0 break else: i += 1
@tigerwoulds ..I am looking to do the exact same thing but I'm getting a bit lost on the upgrade. Can you share your working Python3 script by chance? Thanks!
Awesome work! Glad to hear you reached a solution 🙂
@LongDinh unfortunately, same issue BUT I was able to figure this out using a slightly different method from this example. I converted this to python 3 and replaced the httplib/urllib pieces with the functions from the 'request' library for python 3 and everything is worked as expected. Including the payload as you described initially was key to get this working.
I can now loop through a folder on my GIS Server and update properties/capabilities for all services in the folder.
Big thank you for your help again.
Thanks for the reply. I dont think this will work for us me as I have several hundreds of layers to publish as individual services. Setting up the service definition file for each one is not feasible.
The bulk publishing doc I referenced is a good solution to publish these quickly, but I just need a way to update the feature service properties once the services are published.
They are all 'registered' services pulling from a SDE database so unfortunately using the update_definition() function outlined here doesnt work. Service definitions | ArcGIS Developer
I think I'm getting there. Still very new to python and programming in general so I appreciate the help.
Here is my code overall:
import requestsimport osimport jsonimport sslssl._create_default_https_context = ssl._create_unverified_context# Get token from /arcgis/sharing/rest/generateTokentoken = "####"service_name="TestService"folder_name="TestFolder"domain="######################"edit_service_url = f"https://{domain}/arcgis/admin/services/{folder_name}/{service_name}.MapServer/edit"print (edit_service_url)base_dir = r"C:\Test"json_file = os.path.join(base_dir, r"myServicePropertiesX.json")from os.path import existsfile_exists = exists(json_file)print (file_exists)with open(json_file) as jf: service_json=json.load(jf)payload = {'f': 'json', 'service':service_json, 'token':token}response = requests.post( edit_service_url, data=payload)print(response.json)
For Enterprise services, you could try editing the service properties through the ArcGIS Admin API. See notes on the endpoint here: https://developers.arcgis.com/rest/enterprise-administration/enterprise/edit-service.htm . I believe you are looking to enable (set true) the "typename":"FeatureServer object.
Using Python:
import requests import os import json # Get token from /arcgis/sharing/rest/generateToken token = "###" service_name="myservice" folder_name="myfoldername" domain="myarcgis.com" edit_service_url = f"https://{domain}/arcgis/admin/{folder_name}/{service_name}.MapServer/edit base_dir = r"C:/workspace" json_file = os.path.join(base_dir, r"myServiceProperties.json") with open(json_file) as jf: service_json=json.load(jf) payload = { 'f': 'json', 'service':service_json, 'token':'token } response = requests.post( edit_service_url, data=payload ) print(response.json())
Thanks! Curious if this will work for non hosted services..aka service that are registered with an SDE database. The doc states you can update service properties for hosted feature layers
Hi @tigerwoulds,
You might be able to update the definition using Python. Here are the reference notes from the developers site: https://developers.arcgis.com/python/guide/updating-feature-layer-properties/
If the the bulk publish publishes a Feature Layer but with editing disabled, I believe you search for it in portal and update the 'capabilities' property to enable create/delete/query/update. The capability definition is something like:
cap_def_update = {'capabilities':'Create,Delete,Query,Update,Editing,Extract'}
Hope this helps 😃 Good luck!
Hi @tigerwoulds
I was able to enable editing for bulk service publishing using Python, by following this workflow:
- using Pro project Map, create web layer sharing draft using "getWebLayerSharingDraft" function- configure the sharing draft as required, like the federated server URL, copy data to server or not, according to your needs- export the draft to a file using "exportToSDDraft" function- edit the exported file to enable editing then save the file- stage the service using "StageService_server" function- publish the service using "UploadServiceDefinition_server" function
I am attaching the function that can help editing the service draft file.Hope that helps in what you are after
RegardsIhab
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.