Update CSV item in ArcGIS

This notebook uses the ArcGIS API for Python. For more information, see the ArcGIS API for Python documentation and guides.

ArcGIS Survey123 utilizes CSV data in several workflows, including external choice lists, the search() appearance, and pulldata() calculations. When you need to periodically update the CSV content used in a survey, a useful method is to upload the CSV files to your ArcGIS organization and link the CSV items to your survey. Once linked, any updates to the CSV items will automatically pull through to your survey without the need to republish the survey. To learn more about linking items to a survey, see Linked content.

This notebook demonstrates how to automate updating a CSV item in your ArcGIS organization.

Note: It is recommended to run this notebook on your computer in Jupyter Notebook or ArcGIS Pro, as that will provide the best experience when reading locally stored CSV files. If you intend to schedule this notebook in ArcGIS Online or ArcGIS Notebook Server, additional configuration may be required to read CSV files from online file storage, such as Microsoft OneDrive or Google Drive.

In csv_filepaths, specify the directory path and file name for one or more CSV files, separated by a comma.

Specify the username and password for the ArcGIS organizational account that owns the corresponding CSV items in your organization.

For more information on connecting to your ArcGIS organization, see Working with different authentication schemes.

import os
import arcgis
from arcgis.gis import GIS

csv_filepaths = [r"<directory>\employees.csv", r"<directory>\locations.csv"]
gis = GIS(username="username", password="password")

The CSV files in csv_filepaths are looped through, and the name of each CSV file is obtained. The file name is then used to search for the corresponding CSV item in your ArcGIS organization.

Note: The name of the CSV file stored locally must match the file name of the CSV item in your ArcGIS organization. Ensure that there is only one CSV item in your organization with that name. If there are multiple CSV files with the same name, the incorrect item may be updated.

Once the CSV item is found, it is updated with the local version of the CSV file.

for csv_file in csv_filepaths:
    csv_name = os.path.splitext(os.path.basename(csv_file))[0]
    online_item = gis.content.search(query='title: {}'.format(csv_name), item_type='CSV')[0]
    print(online_item.update({}, csv_file))

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.