Files
nusquama 99f16b40cb creation
2025-11-13 13:58:57 +01:00

16 KiB
Raw Permalink Blame History

Automated Web Form Data Collection and Storage to Google Sheets

https://n8nworkflows.xyz/workflows/automated-web-form-data-collection-and-storage-to-google-sheets-8574

Automated Web Form Data Collection and Storage to Google Sheets

1. Workflow Overview

This workflow automates the collection of data submitted via a web form and stores it efficiently into a Google Sheet. It is designed primarily for use cases such as contact form submissions, lead capture, business registrations, or event booking data collection. The workflow ensures data cleanliness, adds submission timestamps, and supports batch processing with controlled pacing to avoid API rate limits.

The logical structure is divided into the following blocks:

  • 1.1 Input Reception: Accepts incoming form submissions via an HTTP POST webhook.
  • 1.2 Data Cleaning and Structuring: Extracts and formats submitted data, adding a submission date.
  • 1.3 Batch Processing Loop: Enables processing multiple entries in batches for scalability.
  • 1.4 Data Storage: Appends cleaned data rows into a configured Google Sheet.
  • 1.5 Throttling: Introduces a delay between batch processing iterations to prevent API overload.

2. Block-by-Block Analysis

1.1 Input Reception

Overview:
This block listens for incoming HTTP POST requests at a unique webhook URL. It acts as the entry point, capturing the raw form submission data.

Nodes Involved:

  • Webhook

Node Details:

  • Webhook
    • Type & Role: HTTP Webhook trigger node; listens for incoming POST requests.
    • Configuration:
      • HTTP Method: POST
      • Path: A unique generated string (/93a81ced-e52c-4d31-96d2-c91a20bd7453)
    • Key Expressions: None, triggers on HTTP POST event.
    • Connections: Outputs to Clean response data node.
    • Edge Cases / Failures:
      • Incorrect HTTP method requests (non-POST) will not trigger.
      • If the webhook path is changed or expired, requests will fail.
      • Missing required form fields in the payload can cause downstream processing errors.
    • Sub-workflow: None.

1.2 Data Cleaning and Structuring

Overview:
Processes the raw JSON payload from the webhook, extracts specific form fields, and appends a submission date. This produces a clean, consistent data object for storage.

Nodes Involved:

  • Clean response data

Node Details:

  • Clean response data
    • Type & Role: Code node executing JavaScript to transform data.
    • Configuration:
      • Extracts fields: business_name, location, whatsapp, email, name from the webhook request body.
      • Adds submitted_date field formatted as YYYY-MM-DD (current date at execution).
      • Returns a simplified JSON object for downstream use.
    • Key Expressions:
      const submitted_at = new Date().toISOString().split('T')[0];
      return [{
        json: {
          business_name: $json.body.business_name,
          location: $json.body.location,
          whatsapp: $json.body.whatsapp,
          email: $json.body.email,
          name: $json.body.name,
          submitted_date: submitted_at,
        }
      }];
      
    • Connections: Input from Webhook, output to Loop Over Items.
    • Edge Cases / Failures:
      • If any expected fields are missing from the webhook body, the cleaned output will have undefined values, potentially causing issues in Google Sheets.
      • Date generation depends on system time; misconfigured server time may affect accuracy.
    • Sub-workflow: None.

1.3 Batch Processing Loop

Overview:
Handles the possibility of multiple items (bulk form submissions) by splitting incoming data into batches and processing them sequentially. Ensures scalability and controlled execution.

Nodes Involved:

  • Loop Over Items

Node Details:

  • Loop Over Items
    • Type & Role: SplitInBatches node; splits input data into individual items or batches for processing.
    • Configuration:
      • Default batch size (implied, not explicitly set).
      • Error handling set to continueRegularOutput to prevent workflow halts on errors.
    • Key Expressions: None; works on incoming array data.
    • Connections: Input from Clean response data, outputs in two branches:
      • Main output: goes to Store Data in Sheet.
      • Second output: empty array (unused).
    • Edge Cases / Failures:
      • If input data is not an array, batching may fail or behave unexpectedly.
      • Large batches without delay may hit API rate limits downstream.
    • Sub-workflow: None.

1.4 Data Storage

Overview:
Appends the cleaned and individual submission data as a new row in a predefined Google Sheet. Uses OAuth2 credentials for authorization.

Nodes Involved:

  • Store Data in Sheet

Node Details:

  • Store Data in Sheet
    • Type & Role: Google Sheets node; appends rows to a specified spreadsheet.
    • Configuration:
      • Operation: Append
      • Document ID: 1jGQybPhdWyDQNU2wvVP__PbxInReSa3dBtw2yTSOWKg (Google Sheet unique ID)
      • Sheet Name: gid=0 (default first sheet)
      • Column mapping:
        • Datesubmitted_date
        • Namename
        • Email (note trailing space) ← email
        • Locationlocation
        • Business Namebusiness_name
        • WhatsApp Numberwhatsapp
      • Mapping Mode: Define columns below (explicit mapping)
      • Does not convert types or attempt type conversion.
    • Credentials: Uses Google Sheets OAuth2 credentials named Google Sheets.
    • Connections: Input from Loop Over Items, output to Wait node.
    • Edge Cases / Failures:
      • Authorization failures if OAuth2 token expires or credentials are revoked.
      • Column name mismatch (especially the trailing space on Email ) will cause data not to populate correctly.
      • API rate limits if many writes happen rapidly without delay.
    • Sub-workflow: None.

1.5 Throttling

Overview:
Introduces a fixed delay (5 seconds) after each append operation to avoid hitting Google Sheets API rate limits or overloading the workflow when processing multiple entries.

Nodes Involved:

  • Wait

Node Details:

  • Wait
    • Type & Role: Wait node; pauses workflow execution for a fixed duration.
    • Configuration:
      • Duration: 5 seconds (default wait time)
    • Connections: Input from Store Data in Sheet, output back to Loop Over Items (continuing the batch processing).
    • Edge Cases / Failures:
      • If the wait node fails or is bypassed, rapid API calls may lead to quota or rate-limit errors.
    • Sub-workflow: None.

3. Summary Table

Node Name Node Type Functional Role Input Node(s) Output Node(s) Sticky Note
Webhook HTTP Webhook Entry point; receives form data Clean response data ## Webhook Trigger The Webhook node acts as the entry point for the workflow. It listens for POST requests sent to a unique path.
Clean response data Code Cleans and structures form data Webhook Loop Over Items ## Clean and Structure Incoming Data Extracts form fields and appends submission date in YYYY-MM-DD format.
Loop Over Items SplitInBatches Batch handling for scalability Clean response data Store Data in Sheet ## Looping for Batch Handling Enables processing multiple submissions one at a time to ensure scalability.
Store Data in Sheet Google Sheets Append data rows to Google Sheet Loop Over Items Wait ## Append Data to Google Sheets Appends structured data to a Google Sheet with mapped columns.
Wait Wait Throttling; introduces delay Store Data in Sheet Loop Over Items ## Wait Adds a 5-second delay to prevent Google Sheets API rate limits or system overload during batch processing.
Sticky Note Sticky Note Documentation Save to Google Sheets via Web Form... (detailed workflow description and requirements)
Sticky Note1 Sticky Note Documentation Webhook trigger details and form fields required.
Sticky Note2 Sticky Note Documentation Explains data cleaning and structuring node logic.
Sticky Note3 Sticky Note Documentation Explains batch processing node usage.
Sticky Note4 Sticky Note Documentation Explains Google Sheets node configuration and mapping.
Sticky Note5 Sticky Note Documentation Explains Wait node purpose and configuration.

4. Reproducing the Workflow from Scratch

  1. Create Webhook Node

    • Add a Webhook node named Webhook.
    • Set HTTP Method to POST.
    • Define a unique webhook path (e.g., 93a81ced-e52c-4d31-96d2-c91a20bd7453).
    • Save and activate the webhook.
  2. Create Code Node for Data Cleaning

    • Add a Code node named Clean response data.
    • Use the following JavaScript code to extract and structure data:
      const submitted_at = new Date().toISOString().split('T')[0];
      return [{
        json: {
          business_name: $json.body.business_name,
          location: $json.body.location,
          whatsapp: $json.body.whatsapp,
          email: $json.body.email,
          name: $json.body.name,
          submitted_date: submitted_at,
        }
      }];
      
    • Connect the Webhook nodes main output to this nodes input.
  3. Add SplitInBatches Node for Looping

    • Add a SplitInBatches node named Loop Over Items.
    • Leave batch size to default (usually 1) or configure as per expected batch size.
    • Set Error Handling to continueRegularOutput to avoid workflow interruption on errors.
    • Connect Clean response data output to Loop Over Items input.
  4. Add Google Sheets Node to Append Data

    • Add a Google Sheets node named Store Data in Sheet.
    • Configure operation as append.
    • Set Document ID to your target Google Sheet ID.
    • Set Sheet Name as gid=0 or your sheets actual name.
    • Map columns explicitly as follows:
      • Business Namebusiness_name
      • Locationlocation
      • WhatsApp Numberwhatsapp
      • Email (note trailing space) ← email
      • Namename
      • Datesubmitted_date
    • Select your connected Google Sheets OAuth2 credential.
    • Connect Loop Over Items main output to this nodes input.
  5. Add Wait Node for Throttling

    • Add a Wait node named Wait.
    • Configure it to delay for 5 seconds.
    • Connect Store Data in Sheet output to this node input.
    • Connect Wait node output back to Loop Over Items node input to continue processing batches sequentially.
  6. Final Workflow Setup

    • Verify all nodes are connected as per above steps:
      WebhookClean response dataLoop Over ItemsStore Data in SheetWaitLoop Over Items
    • Activate the workflow.
    • Test by submitting POST requests to the webhook URL with required form fields:
      • business_name
      • location
      • whatsapp
      • email
      • name

5. General Notes & Resources

Note Content Context or Link
Workflow requires Google Sheets OAuth2 credentials set up in n8n with edit access to the target spreadsheet. Credential setup in n8n
Google Sheet must have columns exactly as follows (case-sensitive, including the trailing space for Email ): Business Name, Location, WhatsApp Number, Email , Name, Date Sample Google Sheet
Webhook path is unique and should be secured or changed if exposed publicly. Security best practice
The Wait node is critical to avoid hitting Google Sheets API rate limits when processing multiple items quickly. Adjust delay as needed based on usage. Performance tuning
The trailing space in the Email column name is intentional due to the existing sheet structure and must be matched exactly for data to populate. Important detail for data mapping
This workflow is ideal for single or batch form submissions; batch handling can be disabled by removing the Loop Over Items node if not needed. Use case guidance

Disclaimer: The text provided is exclusively derived from an automated n8n workflow. The content respects all applicable content policies and contains no illegal or offensive material. All processed data is legal and public.