Select to view content in your preferred language

arcgis.features.table.append() not working with an AGOL Hosted Table as target, and CSV item or Published CSV Hosted Table as source

315
2
09-03-2024 01:03 PM
Labels (1)
gis_bCapell
Occasional Contributor

Using ArcGIS API for Python V 2.3.0 I cannot append a CSV item or hosted table published from that CSV item to records to another hosted table. 

The target table is a table in a feature layer with other tables and features. The CSV was prepared with the same schema as the target table and uploaded from a local file to AGOL. I attempted to publish the csv so that I could append the hosted table created from publishing to another hosted table but my three attempts below failed.

The final attempt using arcpy.management.Append() was a last ditch effort that actually worked by passing the service urls. 

Can someone help me figure out why the ArcGIS API for Python isn't working in this case? 

I had a more complex set of functions that enables this process but simplified the code for this post below.

 

 

import arcgis
import arcpy

gis = GIS()
item_id = 'xyz'
acc_table = 1

dest_table = gis.content.get(item_id).tables[acc_table]

csv_item =  cm.add(item_properties = {
                'type': 'CSV',
                'title': title,
                'tags': '',
                'typeKeywords': "CSV"
            },
                data = local_csv_file)
analyzed = gis.content.analyze(item=csv_item)
publish_params = analyzed['publishParameters']
publish_params['name'] = title
publish_params['locationType'] = None
published_item = csv_item.publish(publish_params)

#1
dest_table.append(item_id = published_table.id, upload_format = 'featureCollection', source_table_name = published_table.tables[0].properties.name)
#2
dest_table.append(item_id = published_table.id, upload_format = 'featureService', source_table_name = published_table.tables[0].properties.name)
#3
dest_table.append(item_id = csv_item.id, upload_format = 'csv', source_table_name = csv_item.name, source_info = publish_params, update_geometry = False)

#Works
arcpy.management.Append(published_table.tables[0].url, dest_table.url, "NO_TEST")

 

 

2 Replies
Clubdebambos
Frequent Contributor

Hi @gis_bCapell 

for your append, try the below...where your source_info is the object returned from the analyze() call, which in your case is the "analyzed" variable.

analyzed = agol.content.analyze(
    item = csv_item.id,
    file_type = "csv",
    geocoding_service = None,
    location_type = None
)

dest_table.append(
    item_id = csv_item.id, # the CSV Item object id
    upload_format = 'csv',
    source_info = analyzed, # the object returned from the analyzed() call
    upsert = False
)

 

No need to publish the CSV item to a Service in this workflow, the CSV item is sufficient. 

Let me know how it goes.

~ learn.finaldraftmapping.com
0 Kudos
gis_bCapell
Occasional Contributor

Interesting approach. Thanks for the feedback. I have moved on from this workflow, but will consider this if I encounter it again.

0 Kudos