<?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 Re: Overwriting Hosted Feature Service from Postgres Feature Class in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwriting-hosted-feature-service-from-postgres/m-p/1281419#M8626</link>
    <description>&lt;P&gt;Well, for me all I do is make sure my directory holding my .py files is shared and then I just have task scheduler run python.exe as the Action:&lt;/P&gt;&lt;P&gt;C:\Users\yourname\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\python.exe&lt;/P&gt;&lt;P&gt;and for the argument supply the python file using the UNC path&lt;/P&gt;&lt;P&gt;\\MyComputerName\BatchDBTasksAE\SqlUnScripts\BatchSqlUN_SewerStructJunction.py.&lt;/P&gt;&lt;P&gt;The python snippet above is configured for the IDLE, not Notebook, so you can just change the GIS param to match your portal and change the sd file location to your directory location and it will run no problem in the IDLE.&lt;/P&gt;&lt;P&gt;When the above works for you, please mark it as correct thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2023 18:36:05 GMT</pubDate>
    <dc:creator>DavidColey</dc:creator>
    <dc:date>2023-04-21T18:36:05Z</dc:date>
    <item>
      <title>Overwriting Hosted Feature Service from Postgres Feature Class</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwriting-hosted-feature-service-from-postgres/m-p/1281271#M8620</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Using the ArcGIS API for Python I'm trying to create a script that overwrites, or re-publishes, the contents of a hosted feature service.&lt;/P&gt;&lt;P&gt;Using ArcGIS Pro 3.1.1, Enterprise 11.0, and PostgreSQL 13.3&lt;/P&gt;&lt;P&gt;Here's my current script:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;from arcgis.gis import GIS&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from arcgis.features import FeatureLayer&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;from arcgis.features import FeatureLayerCollection&lt;/EM&gt;&lt;EM&gt;gis = GIS("&lt;A href="https://ourservername.abc.def/portal" target="_blank"&gt;https://ourservername.abc.def/portal&lt;/A&gt;", username="username", password="password")&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;postgres_fc = r"path to postgresql.sde\featureClass"&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;hosted_fs = gis.content.get('feature service id')&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;hosted_flc = FeatureLayerCollection.fromitem(hosted_fs)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;hosted_flc.manager.overwrite(postgres_fc)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the postgres_fc variable I've tried both a simple, and a fully qualified name (dbname.sde.featureName).&lt;/P&gt;&lt;P&gt;When executed, the script returns "success,", and the timestamp on the hosted feature service is updated,. However the data is unaffected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I missing a step?&amp;nbsp; Is the script completely off the mark?&lt;/P&gt;&lt;P&gt;Any help will be greatly apreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;-Chris&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 13:44:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwriting-hosted-feature-service-from-postgres/m-p/1281271#M8620</guid>
      <dc:creator>Chris_Kell</dc:creator>
      <dc:date>2023-04-21T13:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting Hosted Feature Service from Postgres Feature Class</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwriting-hosted-feature-service-from-postgres/m-p/1281356#M8624</link>
      <description>&lt;P&gt;I would say that if you look at this:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html#arcgis.features.managers.FeatureLayerCollectionManager.overwrite" target="_blank"&gt;https://developers.arcgis.com/python/api-reference/arcgis.features.managers.html#arcgis.features.managers.FeatureLayerCollectionManager.overwrite&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In part, it reads "The data file used to overwrite should be of the same format and filename as the original that was used to publish the layer".&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically you need to create service definition file from your sde layer first. The feature layer is then created from that sd file, and when the sd file is overwritten, both the sd file and feature layer are updated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I prefer to use the sharing module in Pro to create the staging definition (sddraft) and service definition files (sd). Then, instead of jumping over to the api to do the overwrite, just continue to use sharing module in pro.&lt;/P&gt;&lt;P&gt;However, it might look something like this&lt;/P&gt;&lt;P&gt;from arcgis.gis import GIS&lt;BR /&gt;from arcgis.features import FeatureLayerCollection&lt;/P&gt;&lt;P&gt;gis = GIS("&lt;A href="https://yourdomain/yourportal" target="_blank"&gt;https://yourdomain/yourportal&lt;/A&gt;", "username_portal", "user_pw")&lt;/P&gt;&lt;P&gt;try:&lt;BR /&gt;portItems = gis.content.search(query="owner:username_portal", item_type="Feature Layer", sort_field="title", sort_order="asc", max_items=5000) #Service Definition Feature Layer&lt;BR /&gt;for portItem in portItems:&lt;BR /&gt;if (portItem.title == "YourFeatureLayer"):&lt;BR /&gt;portFL = FeatureLayerCollection.fromitem(portItem)&lt;BR /&gt;print (portItem.title)&lt;BR /&gt;portFL.manager.overwrite('C:/ArcProProjects3x/YourSDFile.sd')&lt;BR /&gt;#portFL.manager.refresh()&lt;BR /&gt;print(portFL.properties)&lt;BR /&gt;message = message + "\n" + (portItem.title)&lt;/P&gt;&lt;P&gt;except Exception:&lt;BR /&gt;# If an error occurred, print line number and error message&lt;BR /&gt;import traceback, sys&lt;BR /&gt;tb = sys.exc_info()[2]&lt;BR /&gt;e = sys.exc_info()&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 16:22:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwriting-hosted-feature-service-from-postgres/m-p/1281356#M8624</guid>
      <dc:creator>DavidColey</dc:creator>
      <dc:date>2023-04-21T16:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting Hosted Feature Service from Postgres Feature Class</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwriting-hosted-feature-service-from-postgres/m-p/1281390#M8625</link>
      <description>&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the super fast reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I apologize I left out a key requirement.&amp;nbsp; I'm trying to create this as a Windows scheduled task.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Chris&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 17:17:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwriting-hosted-feature-service-from-postgres/m-p/1281390#M8625</guid>
      <dc:creator>Chris_Kell</dc:creator>
      <dc:date>2023-04-21T17:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: Overwriting Hosted Feature Service from Postgres Feature Class</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/overwriting-hosted-feature-service-from-postgres/m-p/1281419#M8626</link>
      <description>&lt;P&gt;Well, for me all I do is make sure my directory holding my .py files is shared and then I just have task scheduler run python.exe as the Action:&lt;/P&gt;&lt;P&gt;C:\Users\yourname\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\python.exe&lt;/P&gt;&lt;P&gt;and for the argument supply the python file using the UNC path&lt;/P&gt;&lt;P&gt;\\MyComputerName\BatchDBTasksAE\SqlUnScripts\BatchSqlUN_SewerStructJunction.py.&lt;/P&gt;&lt;P&gt;The python snippet above is configured for the IDLE, not Notebook, so you can just change the GIS param to match your portal and change the sd file location to your directory location and it will run no problem in the IDLE.&lt;/P&gt;&lt;P&gt;When the above works for you, please mark it as correct thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 18:36:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/overwriting-hosted-feature-service-from-postgres/m-p/1281419#M8626</guid>
      <dc:creator>DavidColey</dc:creator>
      <dc:date>2023-04-21T18:36:05Z</dc:date>
    </item>
  </channel>
</rss>

