English
Continue in the app
Be The First To Get Support Updates
Want to know about the latest technical content and software updates?

How To: Generate and download ArcGIS Survey123 reports using ArcGIS API for Python

Summary

Generating individual reports in ArcGIS Survey123 is time-consuming if many reports are generated in a single survey form. This task can be automated using the ArcGIS API for Python arcgis.apps.survey123 module. Follow the workflow described in this article to generate and download the ArcGIS Survey123 reports using a stand-alone Python file (.py). The Python file also runs in Jupyter Notebook.

Procedure

  1. Import the necessary modules including the arcgis.apps.survey123 module.
from arcgis.gis import GIS
import os
from zipfile import ZipFile
from arcgis.apps.survey123._survey import SurveyManager, Survey
  1. Specify the ArcGIS Online credential to use.
gis = GIS("https://www.arcgis.com","Username","Password") 
survey_mgr = SurveyManager(gis)
  1. Specify the form ID in ArcGIS Online.
surveyForm = survey_mgr.get("Survey123_Form_ID")
  1. Display all the available print templates for the survey. Refer to ArcGIS Survey123: Report templates for more information.
print(surveyForm.report_templates)
  1. Specify the print template to use. In this example, '0' is used as the first template.
templateChoice = surveyForm.report_templates[0] 
print(templateChoice)
  1. Specify the 'save' folder location.
save_path = r'Folder_Location'
  1. Generate the report and specify the folder ID in ArcGIS Online to store the report and the title.
output = letslearn.generate_report(report_template=choice, folder_id='ArcGIS_Online_Folder_ID', report_title="TestReport")
  1. Store the available reports in a variable.
survey_list = gis.content.search(query='owner:<Owner_name> NOT tags:Print Template', item_type='Microsoft Word')
  1. Iterate through the variable to search all related reports and download them to the folder location specified in Step 6.
for x in survey_list:
    id=x.id
    data_item=gis.content.get(id)
    data_item.download(save_path)
    data_item.delete() #can be removed if the Report is necessary in ArcGIS Online as an item.

The code block below demonstrates the full script.

from arcgis.gis import GIS
import os
from zipfile import ZipFile
from arcgis.apps.survey123._survey import SurveyManager, Survey

gis = GIS("https://www.arcgis.com","User_1","Pass123@") 
survey_mgr = SurveyManager(gis)

letslearn = survey_mgr.get("116aadjdj6kf7hjhv980wh") 

print(letslearn.report_templates) 

choice = letslearn.report_templates[0] 
print(choice)

save_path = r'C:\Users\Username\Desktop\Survey' 

output = letslearn.generate_report(report_template=choice, folder_id='890002c6dsca542jassxceg', report_title="TestReport")

survey_list = gis.content.search(query='owner:<Owner_Name> NOT tags:Print Template', item_type='Microsoft Word')

for x in survey_list:
    id=x.id
    data_item=gis.content.get(id)
    data_item.download(save_path)
    data_item.delete()

Related Information

Last Published: 6/20/2022

Article ID: 000027732

Software: ArcGIS API for Python 2.0.1, 2.0, 1.9.1, 1.9, 1.8.5, 1.8.4, 1.8.3, 1.8.2, 1.8.1, 1.8.0, 1.7.1, 1.7.0, 1.6.1, 1.6 ArcGIS Survey123 Website Current ArcGIS Online Current