<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Overwriting hosted feature layer Enterprise Portal API for Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/overwriting-hosted-feature-layer-enterprise-portal/m-p/1330625#M68910</link>
    <description>&lt;P&gt;I have been using a python script for about a month now that does this for me. All of a sudden it is not working. It gets 3/4ths the way through and gives me this error while attempting to overwrite:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "C:\GIS\scripts\Updating_Web_Layer_Tool_Updated.py", line 138, in &amp;lt;module&amp;gt;&lt;BR /&gt;fs = sdItem.publish(overwrite=True)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 15139, in publish&lt;BR /&gt;serviceitem_id = self._check_publish_status(ret, folder)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 15499, in _check_publish_status&lt;BR /&gt;raise Exception("Job failed.")&lt;BR /&gt;Exception: Job failed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not quite sure what it is asking me to do. Any suggestions. Here is the script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;import os, sys&lt;/P&gt;&lt;P&gt;from arcgis.gis import GIS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prjPath = r"C:\example\Test.aprx"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sd_fs_name = “Feature_Class_Name”&lt;/P&gt;&lt;P&gt;portal = "&lt;A href="https://test.com/portal/" target="_blank"&gt;https://test.com/portal/&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;user = "test@user"&lt;/P&gt;&lt;P&gt;password = "password"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;shrOrg = True&lt;/P&gt;&lt;P&gt;shrEveryone = False&lt;/P&gt;&lt;P&gt;shrGroups = ""&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;relPath = r"C:\example\examples"&lt;/P&gt;&lt;P&gt;sddraft = os.path.join(relPath, "WebUpdate.sddraft")&lt;/P&gt;&lt;P&gt;sd = os.path.join(relPath, "WebUpdate.sd")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print("Creating SD file...")&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;prj = arcpy.mp.ArcGISProject(prjPath)&lt;/P&gt;&lt;P&gt;mp = prj.listMaps()[0]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;arcpy.mp.CreateWebLayerSDDraft(map_or_layers=mp,&lt;/P&gt;&lt;P&gt;out_sddraft=sddraft,&lt;/P&gt;&lt;P&gt;service_name=sd_fs_name,&lt;/P&gt;&lt;P&gt;server_type="HOSTING_SERVER",&lt;/P&gt;&lt;P&gt;service_type="FEATURE_ACCESS",&lt;/P&gt;&lt;P&gt;folder_name=None,&lt;/P&gt;&lt;P&gt;overwrite_existing_service=True,&lt;/P&gt;&lt;P&gt;copy_data_to_server=True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;arcpy.StageService_server(in_service_definition_draft=sddraft,&lt;/P&gt;&lt;P&gt;out_service_definition=sd)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print("Connecting to {}".format(portal))&lt;/P&gt;&lt;P&gt;gis = GIS(portal, user, password)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print("Search for original SD on portal...")&lt;/P&gt;&lt;P&gt;sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]&lt;/P&gt;&lt;P&gt;print("Found SD: {}, ID: {} n Uploading and Overwriting...".format(sdItem.title, sdItem.id))&lt;/P&gt;&lt;P&gt;sdItem.update(data=sd)&lt;/P&gt;&lt;P&gt;print("Overwriting existing feature service...")&lt;/P&gt;&lt;P&gt;fs = sdItem.publish(overwrite=True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if shrOrg or sheEveryone or sheGroups:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Setting sharing options...")&lt;/P&gt;&lt;P&gt;fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print("Finished updateing: {} - ID: {}".format(fs.title, fs.id))&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2023 14:41:29 GMT</pubDate>
    <dc:creator>MatthewSolomon</dc:creator>
    <dc:date>2023-09-20T14:41:29Z</dc:date>
    <item>
      <title>Overwriting hosted feature layer Enterprise Portal API for Python</title>
      <link>https://community.esri.com/t5/python-questions/overwriting-hosted-feature-layer-enterprise-portal/m-p/1330625#M68910</link>
      <description>&lt;P&gt;I have been using a python script for about a month now that does this for me. All of a sudden it is not working. It gets 3/4ths the way through and gives me this error while attempting to overwrite:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "C:\GIS\scripts\Updating_Web_Layer_Tool_Updated.py", line 138, in &amp;lt;module&amp;gt;&lt;BR /&gt;fs = sdItem.publish(overwrite=True)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 15139, in publish&lt;BR /&gt;serviceitem_id = self._check_publish_status(ret, folder)&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 15499, in _check_publish_status&lt;BR /&gt;raise Exception("Job failed.")&lt;BR /&gt;Exception: Job failed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not quite sure what it is asking me to do. Any suggestions. Here is the script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;import os, sys&lt;/P&gt;&lt;P&gt;from arcgis.gis import GIS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;prjPath = r"C:\example\Test.aprx"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sd_fs_name = “Feature_Class_Name”&lt;/P&gt;&lt;P&gt;portal = "&lt;A href="https://test.com/portal/" target="_blank"&gt;https://test.com/portal/&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;user = "test@user"&lt;/P&gt;&lt;P&gt;password = "password"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;shrOrg = True&lt;/P&gt;&lt;P&gt;shrEveryone = False&lt;/P&gt;&lt;P&gt;shrGroups = ""&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;relPath = r"C:\example\examples"&lt;/P&gt;&lt;P&gt;sddraft = os.path.join(relPath, "WebUpdate.sddraft")&lt;/P&gt;&lt;P&gt;sd = os.path.join(relPath, "WebUpdate.sd")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print("Creating SD file...")&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;prj = arcpy.mp.ArcGISProject(prjPath)&lt;/P&gt;&lt;P&gt;mp = prj.listMaps()[0]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;arcpy.mp.CreateWebLayerSDDraft(map_or_layers=mp,&lt;/P&gt;&lt;P&gt;out_sddraft=sddraft,&lt;/P&gt;&lt;P&gt;service_name=sd_fs_name,&lt;/P&gt;&lt;P&gt;server_type="HOSTING_SERVER",&lt;/P&gt;&lt;P&gt;service_type="FEATURE_ACCESS",&lt;/P&gt;&lt;P&gt;folder_name=None,&lt;/P&gt;&lt;P&gt;overwrite_existing_service=True,&lt;/P&gt;&lt;P&gt;copy_data_to_server=True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;arcpy.StageService_server(in_service_definition_draft=sddraft,&lt;/P&gt;&lt;P&gt;out_service_definition=sd)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print("Connecting to {}".format(portal))&lt;/P&gt;&lt;P&gt;gis = GIS(portal, user, password)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print("Search for original SD on portal...")&lt;/P&gt;&lt;P&gt;sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]&lt;/P&gt;&lt;P&gt;print("Found SD: {}, ID: {} n Uploading and Overwriting...".format(sdItem.title, sdItem.id))&lt;/P&gt;&lt;P&gt;sdItem.update(data=sd)&lt;/P&gt;&lt;P&gt;print("Overwriting existing feature service...")&lt;/P&gt;&lt;P&gt;fs = sdItem.publish(overwrite=True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if shrOrg or sheEveryone or sheGroups:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print("Setting sharing options...")&lt;/P&gt;&lt;P&gt;fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;print("Finished updateing: {} - ID: {}".format(fs.title, fs.id))&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:41:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwriting-hosted-feature-layer-enterprise-portal/m-p/1330625#M68910</guid>
      <dc:creator>MatthewSolomon</dc:creator>
      <dc:date>2023-09-20T14:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting hosted feature layer Enterprise Portal API for Python</title>
      <link>https://community.esri.com/t5/python-questions/overwriting-hosted-feature-layer-enterprise-portal/m-p/1331505#M68911</link>
      <description>&lt;P&gt;Hey Matthew,&lt;/P&gt;&lt;P&gt;It might be that there has been a change to permissions on your account, or perhaps an issue with the data.&lt;/P&gt;&lt;P&gt;To help troubleshoot this further can we confirm if manually overwriting the service definition works, or if the script works on other layers?&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 15:46:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwriting-hosted-feature-layer-enterprise-portal/m-p/1331505#M68911</guid>
      <dc:creator>David_McRitchie</dc:creator>
      <dc:date>2023-09-22T15:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting hosted feature layer Enterprise Portal API for Python</title>
      <link>https://community.esri.com/t5/python-questions/overwriting-hosted-feature-layer-enterprise-portal/m-p/1332042#M68912</link>
      <description>&lt;P&gt;If you log in to multiple organizations in arcgis pro, you could try adding arcpy.SignInToPortal(portal, user, password) to your script. Make sure you do so before creating the sddraft.&lt;BR /&gt;&lt;BR /&gt;I had a similar issue while trying to overwrite a service a few months back.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 15:56:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/overwriting-hosted-feature-layer-enterprise-portal/m-p/1332042#M68912</guid>
      <dc:creator>Raul</dc:creator>
      <dc:date>2023-09-25T15:56:19Z</dc:date>
    </item>
  </channel>
</rss>

