<?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: ArcGIS REST API - upload zip file and update hosted feature service (not using arcgis) in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcgis-rest-api-upload-zip-file-and-update-hosted/m-p/1374038#M57059</link>
    <description>&lt;P&gt;I'm actually stuck on something similar enough. It does look like there are 2 operations to do this:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Upload: &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/upload.htm" target="_self"&gt;https://developers.arcgis.com/rest/services-reference/enterprise/upload.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;Append: &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/append-feature-service-.htm" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/rest/services-reference/enterprise/append-feature-service-.htm&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I cannot for the life of me figure out the appropriate parameters for the post request; the response is just the upload item html page. It does look like the order of operations is to upload the shapefile to the feature service, get the item ID, then take the item id and append/upsert. I can do it this the browser just not via script.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Via frontend&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="upload.PNG" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/92671iABF9B903DD8ED3F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="upload.PNG" alt="upload.PNG" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Does not work.&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Upload to our url and get our upload ID
featureservice_url = featureservice_url + "/uploads/upload"

# set req headers
headers = {
    "Content-Type": "multipart/form-data"
}

# Get file and set data parameters
with open(shapefile_loc, 'rb') as f:

    # file upload params
    uploadparams = {
        'item': f,
        'f': json
    }

    r = requests.post(featureservice_url, data=uploadparams, headers=headers)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Wed, 24 Jan 2024 18:43:22 GMT</pubDate>
    <dc:creator>JohnEvans6</dc:creator>
    <dc:date>2024-01-24T18:43:22Z</dc:date>
    <item>
      <title>ArcGIS REST API - upload zip file and update hosted feature service (not using arcgis)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcgis-rest-api-upload-zip-file-and-update-hosted/m-p/1373307#M57017</link>
      <description>&lt;P&gt;I need a Python script that uses ArcGIS REST API to upload a zip file and update a hosted feature service&amp;nbsp;-- NOT using the arcgis package. I trying to follow &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/update-features.htm" target="_self"&gt;Update&lt;/A&gt;.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Here's what I have so far -- but nothing is successfully posting or updating.&amp;nbsp;&lt;/P&gt;&lt;P&gt;import requests&lt;BR /&gt;import json&lt;BR /&gt;import os&lt;BR /&gt;from datetime import datetime&lt;/P&gt;&lt;P&gt;now = datetime.now()&lt;BR /&gt;# dd/mm/YY H:M:S&lt;BR /&gt;dt_string = now.strftime("%m/%d/%Y")&lt;/P&gt;&lt;P&gt;# ArcGIS REST API URL for the item to be updated&lt;BR /&gt;item_id = "itemid"&lt;BR /&gt;url = f"&lt;A href="https://myorg.maps.arcgis.com/sharing/rest/content/items/{item_id}/update" target="_blank"&gt;https://myorg.maps.arcgis.com/sharing/rest/content/items/{item_id}/update&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;# Get token&lt;BR /&gt;baseURL = "&lt;A href="https://www.arcgis.com" target="_blank"&gt;https://www.arcgis.com&lt;/A&gt;"&lt;BR /&gt;loginURL = "&lt;A href="https://www.arcgis.com/sharing/rest/generateToken" target="_blank"&gt;https://www.arcgis.com/sharing/rest/generateToken&lt;/A&gt;".format(baseURL)&lt;BR /&gt;username = "username"&lt;BR /&gt;password = "password"&lt;BR /&gt;expiration = 60&lt;/P&gt;&lt;P&gt;loginparams = {'username': username, 'password': password, 'client': 'referer', 'referer': baseURL, 'expiration': expiration, 'f': 'json'}&lt;BR /&gt;loginresponse = requests.post(loginURL, data=loginparams, verify=False)&lt;BR /&gt;token = loginresponse.json()['token']&lt;/P&gt;&lt;P&gt;# Path to the updated zipped shapefile&lt;BR /&gt;updated_shapefile_path = "C:\\GIS\\myzip.zip"&lt;/P&gt;&lt;P&gt;# Prepare the request headers&lt;BR /&gt;headers = {&lt;BR /&gt;"Content-Type": "multipart/form-data",&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;# Prepare the request parameters&lt;BR /&gt;params = {&lt;BR /&gt;"f": "json",&lt;BR /&gt;"title": f"My layer {dt_string}",&lt;BR /&gt;"description": f"My description - Last downloaded {dt_string}",&lt;BR /&gt;"snippet": f"My snippet - Last updated {dt_string}",&lt;BR /&gt;"token": token&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;# Open the shapefile in binary mode&lt;BR /&gt;with open(updated_shapefile_path, "rb") as file:&lt;BR /&gt;files = {"file": (os.path.basename(updated_shapefile_path), file)}&lt;BR /&gt;try:&lt;BR /&gt;response = requests.post(url, params=params, headers=headers, files=files)&lt;BR /&gt;response.raise_for_status()&lt;BR /&gt;if response.status_code == 200:&lt;BR /&gt;print("Shapefile updated successfully.")&lt;BR /&gt;else:&lt;BR /&gt;print(f"Failed to update shapefile. Status code: {response.status_code}")&lt;BR /&gt;print(response.text)&lt;BR /&gt;except requests.exceptions.RequestException as e:&lt;BR /&gt;print(f"Error during shapefile update: {e}")&lt;/P&gt;&lt;P&gt;# Check the response&lt;BR /&gt;if response.status_code == 200:&lt;BR /&gt;print("Shapefile updated successfully.")&lt;BR /&gt;else:&lt;BR /&gt;print(f"Failed to update shapefile. Status code: {response.status_code}")&lt;BR /&gt;print(response.text)&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2024 04:58:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcgis-rest-api-upload-zip-file-and-update-hosted/m-p/1373307#M57017</guid>
      <dc:creator>RichardButgereit</dc:creator>
      <dc:date>2024-01-23T04:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS REST API - upload zip file and update hosted feature service (not using arcgis)</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcgis-rest-api-upload-zip-file-and-update-hosted/m-p/1374038#M57059</link>
      <description>&lt;P&gt;I'm actually stuck on something similar enough. It does look like there are 2 operations to do this:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Upload: &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/upload.htm" target="_self"&gt;https://developers.arcgis.com/rest/services-reference/enterprise/upload.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;Append: &lt;A href="https://developers.arcgis.com/rest/services-reference/enterprise/append-feature-service-.htm" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/rest/services-reference/enterprise/append-feature-service-.htm&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I cannot for the life of me figure out the appropriate parameters for the post request; the response is just the upload item html page. It does look like the order of operations is to upload the shapefile to the feature service, get the item ID, then take the item id and append/upsert. I can do it this the browser just not via script.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Via frontend&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="upload.PNG" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/92671iABF9B903DD8ED3F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="upload.PNG" alt="upload.PNG" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Does not work.&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Upload to our url and get our upload ID
featureservice_url = featureservice_url + "/uploads/upload"

# set req headers
headers = {
    "Content-Type": "multipart/form-data"
}

# Get file and set data parameters
with open(shapefile_loc, 'rb') as f:

    # file upload params
    uploadparams = {
        'item': f,
        'f': json
    }

    r = requests.post(featureservice_url, data=uploadparams, headers=headers)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 24 Jan 2024 18:43:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcgis-rest-api-upload-zip-file-and-update-hosted/m-p/1374038#M57059</guid>
      <dc:creator>JohnEvans6</dc:creator>
      <dc:date>2024-01-24T18:43:22Z</dc:date>
    </item>
  </channel>
</rss>

