<?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: Update Hosted Feature Layer Using JSON from an API -- Not Working in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-hosted-feature-layer-using-json-from-an-api/m-p/1567322#M10956</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;&amp;nbsp;Thank you! I eventually figured it out and posted about how to do it in case others were struggling with the same thing:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/a-timid-coder-s-guide-to-creating-a-polyline/m-p/1507007" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-python-questions/a-timid-coder-s-guide-to-creating-a-polyline/m-p/1507007&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Dec 2024 16:27:50 GMT</pubDate>
    <dc:creator>GIS_utahDEM</dc:creator>
    <dc:date>2024-12-11T16:27:50Z</dc:date>
    <item>
      <title>Update Hosted Feature Layer Using JSON from an API -- Not Working</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-hosted-feature-layer-using-json-from-an-api/m-p/1500392#M10279</link>
      <description>&lt;P&gt;Hello, I am trying to automate overwriting a polyline hosted feature layer using an API. I&amp;nbsp;&lt;EM&gt;think&lt;/EM&gt; I have the correct format for adding features via the json, but where I'm running into trouble is actually publishing/overwriting the features into the feature layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my main code, I am thinking that the issue is occuring in&amp;nbsp;&lt;STRONG&gt;line 39&lt;/STRONG&gt;:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Main function to fetch API, decode polylines, and publish to ArcGIS Online
def main():

    # Make request to API
    response = requests.get(api_url)
    if response.status_code == 200:
        # Assuming API response is JSON with 'features' containing polyline data
        features = response.json()
        

        # Extract features from the API data
        #features = api_data.get('features', [])

        #if not features:
        #    print("No features found in API response.")
        #    return

        try:
            # Truncate existing features in the feature layer
            feature_layer.manager.truncate()

            # Prepare new features to add
            geojson_features = []
            for feature in features:
                encoded_polyline = feature.get('EncodedPolyline')
                description = feature.get('Description')

                if encoded_polyline and description:
                    # Decode polyline from 'EncodedPolyline' field
                    decoded_polyline = decode_polyline(encoded_polyline)

                    # Convert to GeoJSON Feature format
                    geojson_feature = to_geojson_feature(decoded_polyline, description)
                    
                    geojson_features.append(geojson_feature)

            # Add new GeoJSON features to the feature layer
            print(json.dumps(geojson_features))
            result = feature_layer.edit_features(adds=json.dumps(geojson_features))

            print(f"Features updated successfully in ArcGIS Online hosted feature layer.")

        except Exception as e:
            print(f"Failed to update feature layer: {str(e)}")

    else:
        print("Failed to fetch data from API.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;&lt;STRONG&gt;print(json.dumps(geojson_features)&lt;/STRONG&gt; returns this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[{"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[40.77248, -111.8377], [40.77254, -111.83776], [40.7728, -111.83804], [40.7728, -111.83804], [40.77282, -111.83803], [40.77285, -111.83802], [40.77286, -111.83802], [40.77288, -111.83802], [40.77248, -111.8377]]}, "properties": {"Description": "Blue Detour"}}, {"type": "Feature", "geometry": {"type":.................&lt;/PRE&gt;&lt;P&gt;***I have removed most of the coordinates for simplicity, and only show the first feature though there are more&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error I get, which I believe is in reference to&amp;nbsp;&lt;STRONG&gt;result = feature_layer.edit_features(adds=json.dumps(geojson_features))&lt;/STRONG&gt; is:&lt;/P&gt;&lt;PRE&gt;pass in features as list of Features, dicts or PropertyMap
Parameters not valid for edit_features&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 15:58:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/update-hosted-feature-layer-using-json-from-an-api/m-p/1500392#M10279</guid>
      <dc:creator>GIS_utahDEM</dc:creator>
      <dc:date>2024-07-02T15:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Update Hosted Feature Layer Using JSON from an API -- Not Working</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-hosted-feature-layer-using-json-from-an-api/m-p/1543739#M10719</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/431239"&gt;@GIS_utahDEM&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;The edit_features is expecting a FeatureSet, see docs &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.edit_features" target="_blank" rel="noopener"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;You would need to parse your GeoJSON to create a list of dictionaries that represent a FeatureSet and each Feature would look similar to the below. You could then feed the list of dictionaries (features) into the edit_features() method.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;new_features = [
    {
        "geometry": {
          # geometry details
        },
        "attributes": {
            "str_att_name" : "attribute_value",
            "num_att_name" : 0
        }
    }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively, take a look at the &lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.append" target="_blank" rel="noopener"&gt;append()&lt;/A&gt; method which does allow GeoJSON to be appended.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 09:14:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/update-hosted-feature-layer-using-json-from-an-api/m-p/1543739#M10719</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2024-09-30T09:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Update Hosted Feature Layer Using JSON from an API -- Not Working</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/update-hosted-feature-layer-using-json-from-an-api/m-p/1567322#M10956</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/417766"&gt;@Clubdebambos&lt;/a&gt;&amp;nbsp;Thank you! I eventually figured it out and posted about how to do it in case others were struggling with the same thing:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/a-timid-coder-s-guide-to-creating-a-polyline/m-p/1507007" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-python-questions/a-timid-coder-s-guide-to-creating-a-polyline/m-p/1507007&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 16:27:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/update-hosted-feature-layer-using-json-from-an-api/m-p/1567322#M10956</guid>
      <dc:creator>GIS_utahDEM</dc:creator>
      <dc:date>2024-12-11T16:27:50Z</dc:date>
    </item>
  </channel>
</rss>

