0

As the title, I got some problem when trying to automate response google forms type collect submitter data but I am not the form's owner Here is the form: Sample Form

Below is my scratch code in GAS:

function submitToGoogleFormWithEmail() {
    var formUrl = "https://docs.google.com/forms/d/e/1FAIpQLSdBdRIYCAaxp2FI4n0rVZywcz0Br7n2DOBOIcWSLHP9B67ikA/formResponse";
    var email = Session.getActiveUser().getEmail();
    var token = ScriptApp.getOAuthToken();
    Logger.log(token);

    var payload = {
        "entry.1507679348": "lucasdo",
        "entry.21751216": "dnd",
        "entry.528181198": "appscript",
        "emailAddress": email
    };

    var options = {
        'method': 'post',
        "muteHttpExceptions": true,
        'payload': payload,
        'headers': {
            'Authorization': 'Bearer ' + token,
            'Accept': 'application/x-www-form-urlencoded'
        }
    };

    var response = UrlFetchApp.fetch(formUrl, options);
    Logger.log(response.getResponseCode());
}

When I test the code, it showed error code 401 in console log of app script. Console Log Screenshot

I tried with browser console fetching, it worked if I logged in before and go to below url: https://docs.google.com/forms/d/e/1FAIpQLSdBdRIYCAaxp2FI4n0rVZywcz0Br7n2DOBOIcWSLHP9B67ikA/formResponse?entry.1507679348=lucasdo&entry.21751216=dnd&entry.528181198=appscript&[email protected]

Similar thread but not helpful so much: How to auto submitting in require sign-in google form from google apps script

Does anyone have the solution for this case?

12
  • Welcome to StackOverflow! May I ask if you want to get all the emails of the people who responded to the form?
    – Jats PPG
    Commented Nov 18, 2024 at 16:34
  • 1
    Why are you using an HTTP Post request instead of the Forms Service?
    – Wicket
    Commented Nov 18, 2024 at 23:44
  • This might help Post request failed with error code 400 when submitting Google form
    – Wicket
    Commented Nov 19, 2024 at 0:15
  • It appears that the Form Settings for "Responses">"Collect email addresses" has been set to Verified. This required two things for the respondent: 1) they are required to login to Google and 2) they are required to physically check the box with the text " Record <<google email address>> as the email to be included with my response. This email address is subsequently catted and passed to a linked spreadsheet BUT when one looks at the "items" in the Form, the "Email address" is not an accessible item. In short, you are trying to update a field that doesn't exist.
    – Tedinoz
    Commented Nov 19, 2024 at 2:12
  • @JatsPPG: I am not the form owner, I just want to submit to another user's form. Commented Nov 19, 2024 at 2:51

1 Answer 1

0

I can't offer a definitive answer about using Google Apps Script server-side code to post a response to a Google Form owned by someone else that is set to collect the form respondent's email address automatically, but I can mention a couple of things.

Regarding your attempts to use the web browser console and extensions, these options are not directly comparable with using Google Apps Script's FetchUrlApp.fetch, first because this method runs on Google's servers while the mentioned options run on the user's device. Second, the Google Apps Script user cannot control all the possibilities for making HTTP requests due to limitations set by Google, i.e., the user-agent can't be customized. For details, see https://developers.google.com/apps-script/reference/url-fetch.

In addition to Google Apps Script, other cloud services, such as https://www.postman.com, can handle HTTP requests. Some of them allow the user to play with more options.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.