Skip to main content

Google Forms Webhook Tutorial

If you need to send webhooks from Google Forms on every submission, you can deploy a script. We’re going to assume you already know what webhooks are but in case you need a refresher, you can check out our “What is a Webhook?” article.

Svix is the enterprise ready webhooks sending service. With Svix, you can build a secure, reliable, and scalable webhook platform in minutes. Looking to send webhooks? Give it a try!

Step 1: Create your form

You'll need a form to start. Either create a new one and add some questions or you can also use a pre-existing form. It will also help you test if you submit some responses.

Step 2: Get your endpoint URL

You'll need an endpoint URL to send the webhook to. Generally, the service you're sending to should provide a webhook endpoint URL. For example, if you were trying to send webhooks to Slack, you could get your Slack webhook URL by following this article.

We're going to be using Svix Play which provides a webhook endpoint for you to test your webhooks.

Step 3: Add the script

Go to your Google Form and click on the three dots in the top right between the Send button and your profile picture. Then select Script Editor.

A text editor should open up. Delete the code and insert the following code:

var ENDPOINT_URL = "Enter your endpoint URL here"

function onSubmit(e) {
var form = FormApp.getActiveForm();
var allResponses = form.getResponses();
var latestResponse = allResponses[allResponses.length - 1];
var response = latestResponse.getItemResponses();
var payload = {};
for (var i = 0; i < response.length; i++) {
var question = response[i].getItem().getTitle();
var answer = response[i].getResponse();
payload[question] = answer;
}

var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
UrlFetchApp.fetch(ENDPOINT_URL, options);
};

Make sure you enter your endpoint URL. The onSubmit function is the function we want to run when the form gets a submission.

Save your changes.

Step 4: Test Your Script

We can test our script by clicking "Run".

You should receive a webhook at your endpoint.

Step 5: Add a Trigger

Click the alarm clock icon in the sidebar (should say Trigger next to it once you hover your cursor over the sidebar). Click the Add Trigger button.

Make sure you've selected your onSubmit function as the function to run, choose which deployment you want to use (if you haven't deployed anything yet just choose Head), event source should be "from form", and select "On form submit" as the event type.

Click Save.

Step 6: Deploy the Script:

Click on the Deploy button in the top right and select New Deployment.

Click on Select type and choose Web app.

You can add a description if you want.

Under Web app choose to execute as yourself and authenticate.

Under Who has access choose Anyone.

Click Deploy.

Congrats! Your Google Form should now be sending a webhook to your endpoint URL whenever it receives a submission.

To recap the steps for Google Form Webhooks:

  1. Create Your Form: Start with a new or existing Google Form.
  2. Get Your Endpoint URL: Obtain an endpoint URL from the service you're sending webhooks to, like Slack or Svix Play.
  3. Add the Script: In your Google Form's Script Editor replace the code with the provided script with your endpoint URL.
  4. Test Your Script: Run the script to check if it works.
  5. Add a Trigger: Set up a trigger in the Script Editor to run the onSubmit function on form submission.
  6. Deploy the Script: Deploy as a web app with execution rights and access settings.