Select to view content in your preferred language

Arcgis API for Python Append Method Error - RuntimeError: Object reference not set to an instance of an object.

2432
7
03-30-2020 06:54 PM
by Anonymous User
Not applicable

Hello - I am trying to append one feature layer to another in ArcGIS Online using the ArcGIS API for Python. Code below. I am receiving the error: RuntimeError: Object reference not set to an instance of an object.
(Error Code: 400)

0 Kudos
7 Replies
GeofyAdmin
Occasional Contributor

well, your flayer is undeclared!

To clarify the proper workflow of what you are trying to do:

1. First get the hosted feature service containing the layer you want to update/append, like this FS=gis.content.get('itemID here')

2. Get the layer like this FL=FS[0] or whatever index/name you have

3. Get the item id of the AGOL item containing source data (could be a shapefile or whatever you have previously uploaded. I am assuming a geojson file) agolId=gis.content.get('itemID here')

4. Now attempt to append like this: ret=FL.append(item_id=agolId, upsert=false, update_geometry=true, upload_format='geojson')

5. Optionally you should check the ret variable to see if success or failire

Finally, fields should match between source and dest. If not, you can make use of the field_mappings prop of the append method

Good luck and check append doc below

arcgis.features module — arcgis 1.8.0 documentation 

0 Kudos
by Anonymous User
Not applicable

My apologies, the flayer is declared above the screenshot I sent. I will try the field mappings. Thank you for the quick response. 

0 Kudos
GeofyAdmin
Occasional Contributor

Sure but also pay attention to the item_id parameter to the append method. 

It’s expecting a certain type of portal item, I.e. an uploaded file: shapefile, geojson etc. 

0 Kudos
by Anonymous User
Not applicable

Is a hosted feature layer an acceptable item? The source dataset is a hosted feature layer that can be seen below.

0 Kudos
GeofyAdmin
Occasional Contributor

a featurecollection would be the closest to your case. 

look at the upload_format of the append method. 

You would need to get a featurecollection out of one of the layers of your hosted feature service

If you run into any issues let me know and I’ll write a working code for you but tomorrow because it’s a bit late where I am

0 Kudos
by Anonymous User
Not applicable

Got it, thank you. A working code showing how to get a featurecollection out of the one layer within the hosted feature layer would be much appreciated. Thank you for the assistance. 

0 Kudos
ChadPeltier
Occasional Contributor

@GeofyAdmin -- if you still have the sample code for this, that would be much appreciated! 

0 Kudos