<?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 Trouble Overwriting Hosted Feature Layer Using JSON from API in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/trouble-overwriting-hosted-feature-layer-using/m-p/1500409#M59974</link>
    <description>&lt;P&gt;Hello, I am trying to automatically overwrite a polyline hosted feature layer using JSON from an API. I&lt;EM&gt; think&lt;/EM&gt; thatI have the correct format for adding the feature layers (shown below), and my issue is with actually publishing/appending the features -- specifically in&amp;nbsp;&lt;STRONG&gt;line 39&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what is returned by the&amp;nbsp;&lt;STRONG&gt;print(json.dumps(geojson_feature)&lt;/STRONG&gt;:&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.77248, -111.8377]]}, "properties": {"Description": "Blue Detour"}}, {"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[40.76466, -111.84503],.............&lt;/PRE&gt;&lt;P&gt;***Note: I removed the majority of the coordinates, as well as the additional features for simplicity&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error that I'm getting, I believe from the&amp;nbsp;&lt;STRONG&gt;result = feature_layer.edit_features(adds=json.dumps(geojson_features))&lt;/STRONG&gt;:&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;&lt;P&gt;Thank you in advance for any suggestions!&lt;/P&gt;</description>
    <pubDate>Tue, 02 Jul 2024 16:28:26 GMT</pubDate>
    <dc:creator>GIS_utahDEM</dc:creator>
    <dc:date>2024-07-02T16:28:26Z</dc:date>
    <item>
      <title>Trouble Overwriting Hosted Feature Layer Using JSON from API</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/trouble-overwriting-hosted-feature-layer-using/m-p/1500409#M59974</link>
      <description>&lt;P&gt;Hello, I am trying to automatically overwrite a polyline hosted feature layer using JSON from an API. I&lt;EM&gt; think&lt;/EM&gt; thatI have the correct format for adding the feature layers (shown below), and my issue is with actually publishing/appending the features -- specifically in&amp;nbsp;&lt;STRONG&gt;line 39&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what is returned by the&amp;nbsp;&lt;STRONG&gt;print(json.dumps(geojson_feature)&lt;/STRONG&gt;:&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.77248, -111.8377]]}, "properties": {"Description": "Blue Detour"}}, {"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[40.76466, -111.84503],.............&lt;/PRE&gt;&lt;P&gt;***Note: I removed the majority of the coordinates, as well as the additional features for simplicity&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error that I'm getting, I believe from the&amp;nbsp;&lt;STRONG&gt;result = feature_layer.edit_features(adds=json.dumps(geojson_features))&lt;/STRONG&gt;:&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;&lt;P&gt;Thank you in advance for any suggestions!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 16:28:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/trouble-overwriting-hosted-feature-layer-using/m-p/1500409#M59974</guid>
      <dc:creator>GIS_utahDEM</dc:creator>
      <dc:date>2024-07-02T16:28:26Z</dc:date>
    </item>
  </channel>
</rss>

