I am trying to upsert features to a layer in a feature layer using the /append endpoint. Even though the structure of my request is the same as in the documentation, I am getting an error:
{'error': {'code': 405, 'message': 'Unable to append data.', 'details': ['Append is not enabled.']}}
I am using a token obtained from OAuth2 which is hosted on the same ArcGIS Online as the data. Token is working, because I can make requests to other endpoints like /applyEdits. Append is also enabled, as I can see it from the response from the ArcGIS Online:
"supportsAppend": true
My python code looks like this:
base_url, layer_id, sublayer_id = ... # initialize some values
oauth_session = ... # creates an OAuth2 session - wrapper around requests library
with open("upsert_feature.json", "r") as f:
arcgis_append_features_url = f"{base_url}/arcgis/rest/services/{layer_id}/FeatureServer/{sublayer_id}/append?f=json&upsert=True"
response = oauth_session.post(arcgis_append_features_url, data={"edits": json.loads(f.read())}, headers={"Content-Type": "application/json"})
print(response.json())
Thanks for help!
Solved! Go to Solution.
You need to add the append capability in your service.
Basically you can do it by the API with update definition and just add "Append" to "capabilities" to the service definition or go through the UI on AGOL:
Thank you for a quick answer! I have seen that post before. I am already using my organization's portal to obtain a token, although not through /generateToken endpoint, just through the /token endpoint. It is important for me to follow the App authentication workflow as the script is part of a service, which does not involve user credentials.
You need to add the append capability in your service.
Basically you can do it by the API with update definition and just add "Append" to "capabilities" to the service definition or go through the UI on AGOL:
Thank you so much! Now it is working. It was misleading to see the
"supportsAppend": true
and having to manually add the operation to the list of operations, but now it works 🙂