I am attempting to edit a script in order to automate updating a hosted feature layer on our Enterprise page. I acquired the script from here:
Automate overwrite web layer, feature class
Updating your hosted feature services with ArcGIS Pro and the ArcGIS API for Python
How To: Overwrite hosted feature services from ArcGIS Pro to ArcGIS Online using Python
When I run the script, it prints "Creating SD file" and then PRO crashes about a minute later. I have tried running it with PRO closed from IDLE and the get the same result. I have tried tweaking some of the information with the same result, 6 or 7 times now.
This is the script I am running:
import arcpy
import os, sys
from arcgis.gis import GIS
### Start setting variables
# Set the path to the project
prjPath = r"C:\Users\Documents\ArcGIS\Projects\VMRC_TEST\VMRC_TEST.aprx"
# Update the following variables to match:
# Feature service/SD name in arcgis.com, user/password of the owner account
sd_fs_name = "VMRC Data"
portal = "https://MyOrganizationsEnterpriseAddress/e4portal/sharing/rest/content/items/e74a684af7ee45a1b346cf9c6ba1d8c1" # Can also reference a local portal
user = ""
password = ""
# Set sharing options
shrOrg = True
shrEveryone = False
shrGroups = ""
### End setting variables
# Local paths to create temporary content
relPath = r"C:\Users\Documents\ArcGIS\Projects"
sddraft = os.path.join(relPath, "WebUpdate.sddraft")
sd = os.path.join(relPath, "WebUpdate.sd")
# Create a new SDDraft and stage to SD
print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps()[0]
arcpy.mp.CreateWebLayerSDDraft(map_or_layers=mp, out_sddraft=sddraft, service_name=sd_fs_name, server_type="HOSTING_SERVER", service_type="FEATURE_ACCESS", folder_name=None, overwrite_existing_service=True, copy_data_to_server=True, enable_editing=False, allow_exporting=False, enable_sync=True)
arcpy.StageService_server(sddraft, sd)
print("Connecting to {}".format(portal))
gis = GIS(portal, user, password)
# Find the SD, update it, publish /w overwrite and set sharing and metadata
print("Search for original SD on portal…")
sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]
print("Found SD: {}, ID: {} n Uploading and overwriting…".format(sdItem.title, sdItem.id))
sdItem.update(data=sd)
print("Overwriting existing feature service…")
fs = sdItem.publish(overwrite=True)
if shrOrg or shrEveryone or shrGroups:
print("Setting sharing options…")
fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)
print("Finished updating: {} – ID: {}".format(fs.title, fs.id))
One thing I am also not clear about it if I am using PRO while I run the script, and logged onto our enterprise portal, do I need the username and password filled in? We use an API key for ours, so there is no username and password in order to log on our Enterprise site.
For the portal= name, I have it pointing directly to my content page. Could that be messing it up?
Thank you.