I've been trying @AmandaBishop2018 's script above with @NicolasMarecos edit but keep running into issues.
Script: as entered
import arcpy
import os, sys
from arcgis.gis import GIS
### Start setting variables
# Set the path to the project
prjPath = r"Z:\ArcMap\UpdateHosted\UpdateHosted.aprx"
# Update the following variables to match:
# Feature service/SD name in arcgis.com, user/password of the owner account
sd_fs_name = "Test_Feature"
portal = "https://parkcity.maps.arcgis.com" # Can also reference a local portal
user = "devin.boyle"
password = "********"
# Set sharing options
shrOrg = True
shrEveryone = False
shrGroups = ""
### End setting variables
# Local paths to create temporary content
relPath = sys.path[0]
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(mp, sddraft, sd_fs_name, "MY_HOSTED_SERVICES", "FEATURE_ACCESS","", True, True, allow_exporting=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(query="title:"+ sd_fs_name + " AND owner: " + 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)
But I always end up with these results:
IndentationError Traceback (most recent call last)
File C:\Program Files\Arcgis\Pro\bin\Python\envs\arcgispro-py3\lib\ast.py, in parse:
Line 35: return compile(source, filename, mode, PyCF_ONLY_AST)
IndentationError: expected an indented block (<string>, line 49)