I am trying to use the REST API from ArcGIS Online to refresh or overwrite a feature service.
I am using Python to upload an item using the addItem operation:
upload_url = ( f"{portal}/sharing/rest/content/users/{username}/{folder_id}/addItem" ) params = { "f": "json", "token": token, "type": "GeoPackage", "title": title, "tags": tags, "description": description, "overwrite": "true", } files = {"file": (filename, data)} response = requests.post(upload_url, files=files, data=params)
Afterwards, I can publish the item using the publish operation:
publish_url = f"{portal}/sharing/rest/content/users/{username}/publish" publish_params = { "f": "json", "token": token, "itemID": item_id, "filetype": "geopackage", "overwrite": "true", "publishParameters": ( f'{{"name": "{name}", "layerInfo": {{"capabilities": "Query"}}}}' ), } # Publish the item publish_response = requests.post(publish_url, data=publish_params)
When I get new data, I want to update the data. I was able to do it for the item with the update operation:
update_url = ( f"{portal}/sharing/rest/content/users/{username}/items/{item_id}/update" ) files = {"file": data} params = { "f": "json", "token": token, } response = requests.post(update_url, files=files, data=params)
However, the associated Feature Service is not updated with the new data, and I cannot figure out which method to use to refresh or overwrite it with the new data. Does anybody know how I can do it using the REST API?
Solved! Go to Solution.
To work around the issue of overwriting or refreshing a feature service using the REST API, you can use the /deleteFeatures and /append methods. The /deleteFeatures method allows you to remove all current features, and the /append method lets you add features from your newly updated data. This approach effectively achieves the same result as overwriting or refreshing the service.
Note: According to ESRI documentation, you cannot overwrite hosted feature services. For more details, see this ESRI Community post. However, in the ArcGIS API for Python, the overwrite method appears to be an option. The code uses the REST API /publish method, which theoretically should not work, but it does. The exact mechanism behind this is unclear for me.
Hi @pzitman, are you able to use the ArcGIS API for Python? If so, here are some scripts you could use:
Hi Jake,
I am using the ArcGIS REST API (https://developers.arcgis.com/rest/users-groups-and-items/user-item-link/) instead of the Python package. I want to minimize dependencies in my environment because it keeps breaking.
To work around the issue of overwriting or refreshing a feature service using the REST API, you can use the /deleteFeatures and /append methods. The /deleteFeatures method allows you to remove all current features, and the /append method lets you add features from your newly updated data. This approach effectively achieves the same result as overwriting or refreshing the service.
Note: According to ESRI documentation, you cannot overwrite hosted feature services. For more details, see this ESRI Community post. However, in the ArcGIS API for Python, the overwrite method appears to be an option. The code uses the REST API /publish method, which theoretically should not work, but it does. The exact mechanism behind this is unclear for me.