DEV Community

Discussion on: Submit a Form to a Google Spreadsheet

Collapse
 
akinhwan profile image
Akinhwan • Edited

Not sure why I'm getting a 400 error? Just for context I'm using vue-form-wizard within a vue.js web app, the following code is in a method i can onComplete of the multi-step form.

submitToGoogleSheet() {
      const scriptURL =
        "https://script.google.com/a/talkaboutdepression.org/macros/s/...../exec";
      const formData = new FormData();
      formData.append("timestamp", new Date());
      formData.append("age", this.age);
      formData.append("gender", this.gender);
      formData.append("marital", this.marital);
      formData.append("ethnicity", this.ethnicity);
      formData.append("totalScore", this.totalScore);
      formData.append("geolocation", this.location);

      fetch(scriptURL, {
        method: "POST",
        mode: "no-cors",
        body: formData,
        headers: {
          "content-type": "multipart/form-data",
        },
      })
        .then((response) => console.log(response))
        .catch((error) => console.error(error.message));
    },

UPDATE 4/14/2020 I realized I had to go back and re run the function
"Now, go to Run > Run Function > initialSetup to run this function."

Thank you! hope anyone else who runs into this tries this first