I am trying to add Features to a Feature Service via REST... previous to this I was trying to delete them and have this post... Thanks @JRhodes
https://community.esri.com/t5/arcgis-api-for-python-questions/grab-sections-of-service-to-process/m-p/1372556#M9552
NOTE: I am writing from my AGOL Enterprise Hosted Feature Layer to an SDE Oracle Feature Class via the Rest Endpoint Feature Service...
Any ideas why Im erroring out?
Note im reading a dictionary for the AGOL address and then the second key is the REST feature service I want to write to....(sourceFC and targetFC)
Any help would be greatly appreciated.
layers_to_append2 = {
"https://services.arcgis.com/p5x3l7/arcgis/rest/services/Inventory/FeatureServer/8/query?sublayer=8" : "https://xyz.gov/env/rest/services/DEV/DEV/FeatureServer/8"
}
def appendLayers2():
for layer in layers_to_append2.keys():
sourceFC = layer
targetFC = layers_to_append2[layer]
where_clause = "1=1"
batch_size = 2000
arcpy.env.preserveGlobalIds = True
query_url = f"{sourceFC}&where={where_clause}&returnIdsOnly=true&f=json&token={agoltoken}"
query_result = requests.get(query_url).json()
object_ids = query_result.get("objectIds", [])
print(object_ids)
if not object_ids:
break # No more features to delete
for i in range(0, len(object_ids), batch_size):
batch_ids = object_ids[i:i + batch_size]
where_clause_with_ids = f"{where_clause} AND OBJECTID >= {min(batch_ids)} AND OBJECTID <= {max(batch_ids)}"
print(where_clause_with_ids)
add_params = {
'where': where_clause_with_ids,
'f': 'json',
'rollbackOnFailure': True,
'token': portaltoken
}
print(add_params)
print("")
response = requests.post(f"{targetFC}/addFeatures", data=add_params)
add_result = response.json()
if 'addResults' in add_result:
added_features = add_result['addResults']
for feature in added_features:
if 'success' in feature and feature['success']:
print(f"Add feature with objectId {feature['objectId']}")
else:
print(f"Failed to add feature with objectId {feature['objectId']}")
else:
print(f"Error adding features. Response: {add_result}")
For some reason it wont write... Do I need to add a "Features" json string to the 'add_params' data load...Looks like the query of the AGOL Feature Layer works as there are only 5 records..BUT the post to add them to the Rest Endpoint errors????
ERROR:
Starting to append: https://services.arcgis.com/xyz/arcgis/rest/services/Inventory/FeatureServer/8
https://services.arcgis.com/xyz/arcgis/rest/services/Inventory/FeatureServer/8/query?where=1=1&sublayer=0&returnIdsOnly=true&f=json&token=wErLJwbDhStxHwstlxyDjKkRSgze-g91Yh9R9PPgzv9GrZfuWuxxxZlKCedGYufGzHZEkl6CAJ5X9Q..
[1, 2, 3, 4, 5]
1=1 AND OBJECTID >= 1 AND OBJECTID <= 5
{'where': '1=1 AND OBJECTID >= 1 AND OBJECTID <= 5', 'f': 'json', 'rollbackOnFailure': True, 'token': 'K0rj4angx4nn3xF0-W0ppQVWdj2rHb27FfPzMKOr5lYCMhslxQ'}
Error adding features. Response: {'error': {'code': 500, 'message': 'Unable to complete operation.', 'details': ['Parser error: Some parameters could not be recognized.']}}