Enabling editing for bulk published feature services

393
17
Jump to solution
4 weeks ago
TigerWoulds
Occasional Contributor II

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 E...

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?

0 Kudos
1 Solution

Accepted Solutions
LongDinh
Occasional Contributor

 

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

}

 

View solution in original post

17 Replies
IhabHassan
Esri Contributor

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

Regards
Ihab

Regards
Ihab
0 Kudos
TigerWoulds
Occasional Contributor II

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

LongDinh
Occasional Contributor

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!

 

0 Kudos
TigerWoulds
Occasional Contributor II

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

0 Kudos
LongDinh
Occasional Contributor

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())

 

 

 

0 Kudos
TigerWoulds
Occasional Contributor II

I think I'm getting there. Still very new to python and programming in general so I appreciate the help. 

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?

In the JSON file, do I just copy the entire map service's JSON ( from sever manager) and edit the Feature Service capabilities section?

Here is my code overall:

import requests
import os
import json

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

# Get token from /arcgis/sharing/rest/generateToken
token = "####"
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 exists

file_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)

 

0 Kudos
LongDinh
Occasional Contributor

 

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

}

 

View solution in original post

TigerWoulds
Occasional Contributor II

Makes sense, thank you much! 

TigerWoulds
Occasional Contributor II

I am getting this message when I run my script. But the feature service service is not updating. Any ideas?

# <bound method Response.json of <Response [200]>

 

0 Kudos