HOW TO

Generate and download ArcGIS Survey123 reports using ArcGIS API for Python

Last Published: June 21, 2022

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()

Article ID: 000027732

Software:
  • ArcGIS Online
  • ArcGIS API for Python 1 x
  • ArcGIS Survey123 Website

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options