HOW TO
Starting with Portal for ArcGIS 10.7.1, users can register user-manager data stores by adding a data store item to the portal. When a user's create data stores items in their portal organization, it allows users to create web layers in bulk from the items inside the enterprise geodatabase.
When items are added or removed from the enterprise geodatabase, users can manually synchronize the enterprise geodatabase with the data store item in the portal. However, some users may want to automate the syncing process using a Python script.
Below is one method to synchronize the data store item with Python:
import urllib, urllib2, json, ssl, arcpy, requests # Generate Portal token username = "<enter user name>" password = "<enter password>" tokenURL = 'https://<enter portal URL>/portal/sharing/rest/generateToken/' param_1 = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'https://<enter portal URL without web adaptor>'} req = urllib2.Request(tokenURL, urllib.urlencode(param_1)) try: response = urllib2.urlopen(req) except: gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) response = urllib2.urlopen(req, context=gcontext) data = json.load(response) token = data['token'] print(token) # Sync the Data Store item in Portal publishURL = 'https://<enter portal URL>/portal/sharing/rest/portals/self/datastores/allDatasets/publishLayers' param_2 = {'datastoreId': '<enter datastore ID>', 'templateSvcConfig': {"serviceName":'null',"type":"MapServer","capabilities":"Map,Query","extensions":[{"typeName":"FeatureServer","capabilities":"Query","enabled":"true","properties":{"maxRecordCount":"4000"}}]}, 'f': 'json', 'token': token} req = urllib2.Request(publishURL, urllib.urlencode(param_2)) try: response = urllib2.urlopen(req) except: gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) response = urllib2.urlopen(req, context=gcontext) data = json.load(response) print('Syncing')
Article ID: 000022854
Get help from ArcGIS experts
Download the Esri Support App