0

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?

asked Feb 13 at 14:26

1 Answer 1

0

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.

answered Feb 20 at 10:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.