Update:
One of the fields was an integer type in the hosted feature service, and the input value from Knack was a string. I changed the field type, but it's still not working. New errors have arisen- one feature's error code is 1003: Operation rolled back and the other is 1000: String or binary data would be truncated. The statement has been terminated.
Original post:
I am working on updating a hosted feature service from a spatial data frame extracted from the Knack API. I used the Python API documentation example posted here.
Script snippet:
svc_lyr = svc_url + "/0"
ft_lyr = FeatureLayer(svc_lyr)
print(ft_lyr)
ft_set = ft_lyr.query(where="1=1")
if len(ft_set) > 0:
print(ft_set.features[0])
template_ = deepcopy(ft_set.features[0])
print(template_)
input_features = []
add_ft = deepcopy(template_)
# records is a list of json records extracted from Knack API with
# attributes, similar to feature set features.
for r in records:
add_ft.attributes['ProjectKey'] = r['ProjectKey']
add_ft.attributes['ProjectName'] = r['ProjectName']
latitude = r['Latitude']
longitude = r['Longitude']
add_ft.geometry = geometry.Geometry({"x" : longitude, "y" : latitude, "spatialReference" : {"wkid" : 4326}})
input_features.append(add_ft)
ft_lyr = FeatureLayer(svc_lyr)
add_result = ft_lyr.edit_features(adds=input_features)
print(add_result)
When I run the script, no data is added and I get the error: {'addResults': [{'objectId': 7, 'uniqueId': 7, 'globalId': None, 'success': False, 'error': {'code': 1000, 'description': 'No mapping exists from object type System.Object[] to a known managed provider native type.'}}], 'updateResults': [], 'deleteResults': []}
I'm not finding much about this error related to this edit_features function... but given that I'm taking a deepcopy() to create the feature template, I'm unsure how the mapping could be off...
Any insights would be much appreciated!