Retrieve forms and responses

The Google Forms API lets you retrieve form content, settings and metadata, and the end-user form responses. This page describes how to perform these tasks.

Before you begin

Perform the following tasks before proceeding with the tasks on this page:

  • Complete authorization/authentication and credentials setup in the Early Adopter Program instructions.

To retrieve the content, settings, and metadata of a form, call the forms.get() method with the form ID.

Python

forms/snippets/retrieve_contents.py
 from 
  
 apiclient 
  
 import 
 discovery 
 from 
  
 httplib2 
  
 import 
 Http 
 from 
  
 oauth2client 
  
 import 
 client 
 , 
 file 
 , 
 tools 
 SCOPES 
 = 
 "https://www.googleapis.com/auth/forms.body.readonly" 
 DISCOVERY_DOC 
 = 
 "https://forms.googleapis.com/$discovery/rest?version=v1" 
 store 
 = 
 file 
 . 
 Storage 
 ( 
 "token.json" 
 ) 
 creds 
 = 
 None 
 if 
 not 
 creds 
 or 
 creds 
 . 
 invalid 
 : 
 flow 
 = 
 client 
 . 
 flow_from_clientsecrets 
 ( 
 "client_secrets.json" 
 , 
 SCOPES 
 ) 
 creds 
 = 
 tools 
 . 
 run_flow 
 ( 
 flow 
 , 
 store 
 ) 
 service 
 = 
 discovery 
 . 
 build 
 ( 
 "forms" 
 , 
 "v1" 
 , 
 http 
 = 
 creds 
 . 
 authorize 
 ( 
 Http 
 ()), 
 discoveryServiceUrl 
 = 
 DISCOVERY_DOC 
 , 
 static_discovery 
 = 
 False 
 , 
 ) 
 # Prints the title of the sample form: 
 form_id 
 = 
 "<YOUR_FORM_ID>" 
 result 
 = 
 service 
 . 
 forms 
 () 
 . 
 get 
 ( 
 formId 
 = 
 form_id 
 ) 
 . 
 execute 
 () 
 print 
 ( 
 result 
 ) 

Node.js

forms/snippets/get_form.js
 'use strict' 
 ; 
 const 
  
 path 
  
 = 
  
 require 
 ( 
 'path' 
 ); 
 const 
  
 google 
  
 = 
  
 require 
 ( 
 '@googleapis/forms' 
 ); 
 const 
  
 { 
 authenticate 
 } 
  
 = 
  
 require 
 ( 
 '@google-cloud/local-auth' 
 ); 
 const 
  
 formID 
  
 = 
  
 '<YOUR_FORM_ID>' 
 ; 
 async 
  
 function 
  
 runSample 
 ( 
 query 
 ) 
  
 { 
  
 const 
  
 auth 
  
 = 
  
 await 
  
 authenticate 
 ({ 
  
 keyfilePath 
 : 
  
 path 
 . 
 join 
 ( 
 __dirname 
 , 
  
 'credentials.json' 
 ), 
  
 scopes 
 : 
  
 'https://www.googleapis.com/auth/forms.body.readonly' 
 , 
  
 }); 
  
 const 
  
 forms 
  
 = 
  
 google 
 . 
 forms 
 ({ 
  
 version 
 : 
  
 'v1' 
 , 
  
 auth 
 : 
  
 auth 
 , 
  
 }); 
  
 const 
  
 res 
  
 = 
  
 await 
  
 forms 
 . 
 forms 
 . 
 get 
 ({ 
 formId 
 : 
  
 formID 
 }); 
  
 console 
 . 
 log 
 ( 
 res 
 . 
 data 
 ); 
  
 return 
  
 res 
 . 
 data 
 ; 
 } 
 if 
  
 ( 
 module 
  
 === 
  
 require 
 . 
 main 
 ) 
  
 { 
  
 runSample 
 (). 
 catch 
 ( 
 console 
 . 
 error 
 ); 
 } 
 module 
 . 
 exports 
  
 = 
  
 runSample 
 ; 

Retrieve all form responses

To retrieve all of the responses from a form, call the forms.responses.list() method with the form ID.

Python

forms/snippets/retrieve_all_responses.py
 from 
  
 apiclient 
  
 import 
 discovery 
 from 
  
 httplib2 
  
 import 
 Http 
 from 
  
 oauth2client 
  
 import 
 client 
 , 
 file 
 , 
 tools 
 SCOPES 
 = 
 "https://www.googleapis.com/auth/forms.responses.readonly" 
 DISCOVERY_DOC 
 = 
 "https://forms.googleapis.com/$discovery/rest?version=v1" 
 store 
 = 
 file 
 . 
 Storage 
 ( 
 "token.json" 
 ) 
 creds 
 = 
 None 
 if 
 not 
 creds 
 or 
 creds 
 . 
 invalid 
 : 
 flow 
 = 
 client 
 . 
 flow_from_clientsecrets 
 ( 
 "client_secrets.json" 
 , 
 SCOPES 
 ) 
 creds 
 = 
 tools 
 . 
 run_flow 
 ( 
 flow 
 , 
 store 
 ) 
 service 
 = 
 discovery 
 . 
 build 
 ( 
 "forms" 
 , 
 "v1" 
 , 
 http 
 = 
 creds 
 . 
 authorize 
 ( 
 Http 
 ()), 
 discoveryServiceUrl 
 = 
 DISCOVERY_DOC 
 , 
 static_discovery 
 = 
 False 
 , 
 ) 
 # Prints the responses of your specified form: 
 form_id 
 = 
 "<YOUR_FORM_ID>" 
 result 
 = 
 service 
 . 
 forms 
 () 
 . 
 responses 
 () 
 . 
 list 
 ( 
 formId 
 = 
 form_id 
 ) 
 . 
 execute 
 () 
 print 
 ( 
 result 
 ) 

Node.js

forms/snippets/get_all_responses.js
 'use strict' 
 ; 
 const 
  
 path 
  
 = 
  
 require 
 ( 
 'path' 
 ); 
 const 
  
 google 
  
 = 
  
 require 
 ( 
 '@googleapis/forms' 
 ); 
 const 
  
 { 
 authenticate 
 } 
  
 = 
  
 require 
 ( 
 '@google-cloud/local-auth' 
 ); 
 const 
  
 formID 
  
 = 
  
 '<YOUR_FORM_ID>' 
 ; 
 async 
  
 function 
  
 runSample 
 ( 
 query 
 ) 
  
 { 
  
 const 
  
 auth 
  
 = 
  
 await 
  
 authenticate 
 ({ 
  
 keyfilePath 
 : 
  
 path 
 . 
 join 
 ( 
 __dirname 
 , 
  
 'credentials.json' 
 ), 
  
 scopes 
 : 
  
 'https://www.googleapis.com/auth/forms.responses.readonly' 
 , 
  
 }); 
  
 const 
  
 forms 
  
 = 
  
 google 
 . 
 forms 
 ({ 
  
 version 
 : 
  
 'v1' 
 , 
  
 auth 
 : 
  
 auth 
 , 
  
 }); 
  
 const 
  
 res 
  
 = 
  
 await 
  
 forms 
 . 
 forms 
 . 
 responses 
 . 
 list 
 ({ 
  
 formId 
 : 
  
 formID 
 , 
  
 }); 
  
 console 
 . 
 log 
 ( 
 res 
 . 
 data 
 ); 
  
 return 
  
 res 
 . 
 data 
 ; 
 } 
 if 
  
 ( 
 module 
  
 === 
  
 require 
 . 
 main 
 ) 
  
 { 
  
 runSample 
 (). 
 catch 
 ( 
 console 
 . 
 error 
 ); 
 } 
 module 
 . 
 exports 
  
 = 
  
 runSample 
 ; 

Retrieve a single form response

To retrieve a specific response from a form, call the forms.responses.get() method with the form ID and the response ID.

Python

forms/snippets/retrieve_single_response.py
 from 
  
 apiclient 
  
 import 
 discovery 
 from 
  
 httplib2 
  
 import 
 Http 
 from 
  
 oauth2client 
  
 import 
 client 
 , 
 file 
 , 
 tools 
 SCOPES 
 = 
 "https://www.googleapis.com/auth/forms.responses.readonly" 
 DISCOVERY_DOC 
 = 
 "https://forms.googleapis.com/$discovery/rest?version=v1" 
 store 
 = 
 file 
 . 
 Storage 
 ( 
 "token.json" 
 ) 
 creds 
 = 
 None 
 if 
 not 
 creds 
 or 
 creds 
 . 
 invalid 
 : 
 flow 
 = 
 client 
 . 
 flow_from_clientsecrets 
 ( 
 "client_secrets.json" 
 , 
 SCOPES 
 ) 
 creds 
 = 
 tools 
 . 
 run_flow 
 ( 
 flow 
 , 
 store 
 ) 
 service 
 = 
 discovery 
 . 
 build 
 ( 
 "forms" 
 , 
 "v1" 
 , 
 http 
 = 
 creds 
 . 
 authorize 
 ( 
 Http 
 ()), 
 discoveryServiceUrl 
 = 
 DISCOVERY_DOC 
 , 
 static_discovery 
 = 
 False 
 , 
 ) 
 # Prints the specified response from your form: 
 form_id 
 = 
 "<YOUR_FORM_ID>" 
 response_id 
 = 
 "<YOUR_RESPONSE_ID>" 
 result 
 = 
 ( 
 service 
 . 
 forms 
 () 
 . 
 responses 
 () 
 . 
 get 
 ( 
 formId 
 = 
 form_id 
 , 
 responseId 
 = 
 response_id 
 ) 
 . 
 execute 
 () 
 ) 
 print 
 ( 
 result 
 ) 

Node.js

forms/snippets/get_single_response.js
 'use strict' 
 ; 
 const 
  
 path 
  
 = 
  
 require 
 ( 
 'path' 
 ); 
 const 
  
 google 
  
 = 
  
 require 
 ( 
 '@googleapis/forms' 
 ); 
 const 
  
 { 
 authenticate 
 } 
  
 = 
  
 require 
 ( 
 '@google-cloud/local-auth' 
 ); 
 const 
  
 formID 
  
 = 
  
 '<YOUR_FORM_ID>' 
 ; 
 const 
  
 responseID 
  
 = 
  
 '<YOUR_RESPONSE_ID>' 
 ; 
 async 
  
 function 
  
 runSample 
 ( 
 query 
 ) 
  
 { 
  
 const 
  
 auth 
  
 = 
  
 await 
  
 authenticate 
 ({ 
  
 keyfilePath 
 : 
  
 path 
 . 
 join 
 ( 
 __dirname 
 , 
  
 'credentials.json' 
 ), 
  
 scopes 
 : 
  
 'https://www.googleapis.com/auth/forms.responses.readonly' 
 , 
  
 }); 
  
 const 
  
 forms 
  
 = 
  
 google 
 . 
 forms 
 ({ 
  
 version 
 : 
  
 'v1' 
 , 
  
 auth 
 : 
  
 auth 
 , 
  
 }); 
  
 const 
  
 res 
  
 = 
  
 await 
  
 forms 
 . 
 forms 
 . 
 responses 
 . 
 get 
 ({ 
  
 formId 
 : 
  
 formID 
 , 
  
 responseId 
 : 
  
 responseID 
 , 
  
 }); 
  
 console 
 . 
 log 
 ( 
 res 
 . 
 data 
 ); 
  
 return 
  
 res 
 . 
 data 
 ; 
 } 
 if 
  
 ( 
 module 
  
 === 
  
 require 
 . 
 main 
 ) 
  
 { 
  
 runSample 
 (). 
 catch 
 ( 
 console 
 . 
 error 
 ); 
 } 
 module 
 . 
 exports 
  
 = 
  
 runSample 
 ; 
Create a Mobile Website
View Site in Mobile | Classic
Share by: