<?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: Add features in a hosted feature layer using Python in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613754#M64696</link>
    <description>&lt;P&gt;Apparently I had an issue with my db - issue is solved&lt;/P&gt;</description>
    <pubDate>Mon, 12 May 2025 18:40:13 GMT</pubDate>
    <dc:creator>HamzaMerini</dc:creator>
    <dc:date>2025-05-12T18:40:13Z</dc:date>
    <item>
      <title>Add features in a hosted feature layer using Python</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613178#M64680</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I created a Hosted Feature Layer in my portal, when I try to add features to this layer using python I get error&amp;nbsp;&lt;STRONG&gt;10500&amp;nbsp;Database error has occurred.&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;Here's the code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer

# Log in to GIS 
gis = GIS("https://myportal.com", "username", "password")

# URL of the hosted feature layer
feature_layer_url = "https://myportal.com/arcgis/rest/services/my_service/FeatureServer/0"

# Access the hosted feature layer
feature_layer = FeatureLayer(feature_layer_url)

# Example: Data to add 
user_data = [
    {"userid": "user_001"},
    {"userid": "user_002"},
    {"userid": "user_003"}
]

# List to store features to be added
features_to_add = []

# Convert the data into the required format for features (attributes)
for user in user_data:
    feature = {
        "attributes": {
            "userid": user["userid"]
        }
    }
    features_to_add.append(feature)

# Add the new features to the hosted feature layer
add_result = feature_layer.edit_features(adds=features_to_add)

# Check the result
if add_result['addResults'][0]['success']:
    print("Features added successfully.")
else:
    print(f"Error: {add_result['addResults'][0].get('error', 'Unknown error')}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to do it as I'm working with a normal layer and maybe this is the issue ?&lt;BR /&gt;The weird thing is that I was able to append data to the layer using a csv (directly from the portal) - but my aim is to use code&lt;BR /&gt;&lt;BR /&gt;I already checked the settings:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HamzaMerini_0-1746783055395.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/131862i33D527C57DCEBCEB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HamzaMerini_0-1746783055395.png" alt="HamzaMerini_0-1746783055395.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Do you have any idea on how I can do it ?&amp;nbsp;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 10:31:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613178#M64680</guid>
      <dc:creator>HamzaMerini</dc:creator>
      <dc:date>2025-05-09T10:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Add features in a hosted feature layer using Python</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613233#M64683</link>
      <description>&lt;P&gt;what do you see if you print the variable 'feature_layer'?&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 14:10:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613233#M64683</guid>
      <dc:creator>ZiqingYu</dc:creator>
      <dc:date>2025-05-09T14:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Add features in a hosted feature layer using Python</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613331#M64686</link>
      <description>&lt;P&gt;I'd recommend printing everything out and just try a simple hardcoded input to test.&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 17:18:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613331#M64686</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2025-05-09T17:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Add features in a hosted feature layer using Python</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613573#M64691</link>
      <description>&lt;P&gt;Here's what the prints look like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HamzaMerini_0-1747039066907.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/131950i426323B3393C20FA/image-size/large?v=v2&amp;amp;px=999" role="button" title="HamzaMerini_0-1747039066907.png" alt="HamzaMerini_0-1747039066907.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Seems normal to me, I get the right data&lt;/P&gt;</description>
      <pubDate>Mon, 12 May 2025 08:38:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613573#M64691</guid>
      <dc:creator>HamzaMerini</dc:creator>
      <dc:date>2025-05-12T08:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add features in a hosted feature layer using Python</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613754#M64696</link>
      <description>&lt;P&gt;Apparently I had an issue with my db - issue is solved&lt;/P&gt;</description>
      <pubDate>Mon, 12 May 2025 18:40:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/add-features-in-a-hosted-feature-layer-using/m-p/1613754#M64696</guid>
      <dc:creator>HamzaMerini</dc:creator>
      <dc:date>2025-05-12T18:40:13Z</dc:date>
    </item>
  </channel>
</rss>

