Select to view content in your preferred language

Overwrite or refresh hosted Feature Service with new data

288
3
Jump to solution
02-13-2025 03:37 AM
Labels (1)
pzitman
Occasional Contributor

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?

0 Kudos
1 Solution

Accepted Solutions
pzitman
Occasional Contributor

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.

View solution in original post

0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor
0 Kudos
pzitman
Occasional Contributor

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.

pzitman
Occasional Contributor

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.

0 Kudos