<?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 Copy features from SDE to AGOL hosted feature layer in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1206676#M7672</link>
    <description>&lt;P&gt;Dear Community,&lt;/P&gt;&lt;P&gt;I want to copy the features from a SDE to a hosted feature layer on AGOL.&lt;/P&gt;&lt;P&gt;My sample so far looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis
import arcpy
from arcgis import GIS
from arcgis.features import FeatureLayer, FeatureSet

fc = r"C:\Sample.sde\SAMPLE.POLY_SAMPLE"
fields = [field.name for field in arcpy.ListFields(fc)]
fields[fields.index("SHAPE")] = "SHAPE@"

user = "???"
password = "???"
item_id = "???"

gis = GIS(r"https://???.maps.arcgis.com/", user, password)
data_id = gis.content.get(item_id)
print(data_id)
layer = FeatureLayer.fromitem(item=data_id, layer_id=0)
print(layer)
layer.manager.truncate()

feature_set = arcpy.FeatureSet()
feature_set.load(fc)
print(feature_set.JSON)

result = layer.edit_features(adds=???)
print(result)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all I delete all features from the hosted feature layer on AGOL.&lt;/P&gt;&lt;P&gt;Next I want to add the features from the SDE feature layer to the hosted feature layer ...&lt;/P&gt;&lt;P&gt;My problem is, that I couldn't find a real working sample for this.&lt;/P&gt;&lt;P&gt;Does anyone have a working sample how to do it?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Daniel.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Aug 2022 10:01:55 GMT</pubDate>
    <dc:creator>dstrigl</dc:creator>
    <dc:date>2022-08-26T10:01:55Z</dc:date>
    <item>
      <title>Copy features from SDE to AGOL hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1206676#M7672</link>
      <description>&lt;P&gt;Dear Community,&lt;/P&gt;&lt;P&gt;I want to copy the features from a SDE to a hosted feature layer on AGOL.&lt;/P&gt;&lt;P&gt;My sample so far looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis
import arcpy
from arcgis import GIS
from arcgis.features import FeatureLayer, FeatureSet

fc = r"C:\Sample.sde\SAMPLE.POLY_SAMPLE"
fields = [field.name for field in arcpy.ListFields(fc)]
fields[fields.index("SHAPE")] = "SHAPE@"

user = "???"
password = "???"
item_id = "???"

gis = GIS(r"https://???.maps.arcgis.com/", user, password)
data_id = gis.content.get(item_id)
print(data_id)
layer = FeatureLayer.fromitem(item=data_id, layer_id=0)
print(layer)
layer.manager.truncate()

feature_set = arcpy.FeatureSet()
feature_set.load(fc)
print(feature_set.JSON)

result = layer.edit_features(adds=???)
print(result)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all I delete all features from the hosted feature layer on AGOL.&lt;/P&gt;&lt;P&gt;Next I want to add the features from the SDE feature layer to the hosted feature layer ...&lt;/P&gt;&lt;P&gt;My problem is, that I couldn't find a real working sample for this.&lt;/P&gt;&lt;P&gt;Does anyone have a working sample how to do it?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Daniel.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 10:01:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1206676#M7672</guid>
      <dc:creator>dstrigl</dc:creator>
      <dc:date>2022-08-26T10:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: Copy features from SDE to AGOL hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1206772#M7675</link>
      <description>&lt;P&gt;I'm sure there are other ways, but using arcpy append is working for me.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;arcpy.management.Append(r"\\pathtosde\signs.sde\Posts", "https://urltofeatureservice/SSA_Map_Data/FeatureServer/1", "TEST", None, '', '')&lt;/LI-CODE&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 15:10:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1206772#M7675</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-08-26T15:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Copy features from SDE to AGOL hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1206787#M7677</link>
      <description>&lt;P&gt;Thanks for your fast response, but I can't use the URL as the target (second parameter), because the hosted feature layer on ArcGIS Online is only available after login (see sample above).&lt;/P&gt;&lt;P&gt;I tried to pass the "layer" from here&lt;/P&gt;&lt;LI-CODE lang="python"&gt;layer = FeatureLayer.fromitem(item=data_id, layer_id=0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;but this failed &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Daniel.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 15:38:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1206787#M7677</guid>
      <dc:creator>dstrigl</dc:creator>
      <dc:date>2022-08-26T15:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Copy features from SDE to AGOL hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1206868#M7681</link>
      <description>&lt;P&gt;But you are logging in on line 14.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works for me, though I pass it the item id of my hosted feature layer.&lt;/P&gt;&lt;P&gt;It will truncate the layer, then append the data from the SDE feature class to the newly truncated hosted feature layer ( I use the "TEST" option as my fields/schema match):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from arcgis.gis import GIS

fc = r"C:\Sample.sde\SAMPLE.POLY_SAMPLE"  # FC holding data to append to FeatureLayer

gis = GIS(url='https://????.maps.arcgis.com/', username='AdminUser', password='UserPass') #sign in to AGOL

feature_layer = gis.content.get('63644981afa0438e97sgd68fs79gs19ec')  # Establish the working dataset by itemid

FeatLay = feature_layer.layers[0] # Grab the first layer in the dataset
FeatLayUrl = FeatLay.url # grab URL as arcpy append uses string value

FeatLay.manager.truncate()

arcpy.management.Append(fc, FeatLayUrl, "TEST", None, '', '')&lt;/LI-CODE&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 18:10:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1206868#M7681</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-08-26T18:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Copy features from SDE to AGOL hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1209680#M7706</link>
      <description>&lt;P&gt;Thanks for your hint, I will try it ...&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 14:36:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1209680#M7706</guid>
      <dc:creator>dstrigl</dc:creator>
      <dc:date>2022-09-05T14:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Copy features from SDE to AGOL hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1601024#M11278</link>
      <description>&lt;P&gt;Rhett:&lt;/P&gt;&lt;P&gt;I used your code to get FeatLayUrl, but I then get the following error message when appending to AGOL even though I have already connected to AGOL to truncate the records in the hosted feature layer.&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "C:\GIS\AGOL_Update.py", line 40, in &amp;lt;module&amp;gt;&lt;BR /&gt;arcpy.management.Append(fc, FeatLayUrl, "TEST", None, '', '')&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 7545, in Append&lt;BR /&gt;raise e&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 7542, in Append&lt;BR /&gt;retval = convertArcObjectToPythonObject(gp.Append_management(*gp_fixargs((inputs, target, schema_type, field_mapping, subtype, expression, match_fields, update_geometry), True)))&lt;BR /&gt;File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in &amp;lt;lambda&amp;gt;&lt;BR /&gt;return lambda *args: val(*gp_fixargs(args, True))&lt;BR /&gt;arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000732: Target Dataset: Dataset &lt;A href="https://server" target="_blank" rel="noopener"&gt;https://server&lt;/A&gt;&amp;nbsp;URL/FeatureServer/0 does not exist or is not supported&lt;BR /&gt;Failed to execute (Append).&lt;/P&gt;&lt;P&gt;Any idea why the code would be throwing this error?&lt;/P&gt;&lt;P&gt;From further testing, it looks like this is caused by running the python script on a computer where ArcGIS Pro had not been logged into AGOL and editing had not been enabled on the hosted feature layer.&lt;/P&gt;&lt;P&gt;When editing did get enabled, the python based Append process was very slow (several days for a million records).&lt;/P&gt;&lt;P&gt;When I logged into AGOL in ArcGIS Pro and closed out of ArcGIS Pro, the python based Append process was relatively fast (15-18 minutes for a million records).&lt;/P&gt;&lt;P&gt;I do not understand why I needed to log into ArcGIS Pro in order to get much better speed as the python script requires AGOL credentials itself to access the hosted feature layer.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2025 15:20:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/copy-features-from-sde-to-agol-hosted-feature/m-p/1601024#M11278</guid>
      <dc:creator>MikeVolz</dc:creator>
      <dc:date>2025-04-03T15:20:28Z</dc:date>
    </item>
  </channel>
</rss>

