diff --git a/forms-api/snippets/README.md b/forms-api/snippets/README.md new file mode 100644 index 000000000..17026ac9c --- /dev/null +++ b/forms-api/snippets/README.md @@ -0,0 +1,4 @@ +The Google Forms API is currently in Restricted Beta. To use the API and these +samples prior to General Availability, your Google Cloud project must be +allowlisted. To request that your project be allowlisted, complete the +[Early Adopter Program application](https://developers.google.com/forms/api/eap). diff --git a/forms-api/snippets/retrieve_all_responses.gs b/forms-api/snippets/retrieve_all_responses.gs new file mode 100644 index 000000000..688adecdd --- /dev/null +++ b/forms-api/snippets/retrieve_all_responses.gs @@ -0,0 +1,35 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + # [START forms_retrieve_all_responses] + function callFormsAPI() { + Logger.log('Calling the Forms API!'); + var formId = ''; + + // Get OAuth Token + var OAuthToken = ScriptApp.getOAuthToken(); + Logger.log('OAuth token is: ' + OAuthToken); + var formsAPIUrl = 'https://forms.googleapis.com/v1beta/forms/' + formId + '/' + 'responses'; + Logger.log('formsAPIUrl is: ' + formsAPIUrl); + var options = { + 'headers': { + Authorization: 'Bearer ' + OAuthToken, + Accept: 'application/json' + }, + 'method': 'get' + }; +var response = UrlFetchApp.fetch(formsAPIUrl, options); + Logger.log('Response from forms.responses was: ' + response); +} +# [END forms_retrieve_all_responses] \ No newline at end of file