Automated Google Document Generation from Form Submissions - n8n Workflow

Use this powerful n8n workflow to automatically generate dynamic Google Documents from submitted forms. Learn how to map form fields to Google Doc n8n templates using the Google Docs API in your n8n automation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users who need to instantly generate personalized documents (e.g., invoices, certificates, contracts) upon form submission.
Technical users looking for a robust document generation solution using the Google Docs API within an n8n workflow.
n8n automation specialists seeking advanced examples of using the Code n8n node for data transformation.
Businesses relying on n8n templates for efficient GSuite automation.

Overview

Generating customized documents manually can be time-consuming and error-prone. This n8n automation solves this by creating a dynamic, serverless document creation pipeline. The core value of this n8n workflow is its ability to map arbitrary form fields directly into Google Doc n8n templates, using specialized data formatting within Code n8n nodes to meet the specific requirements of the Google Docs batchUpdate API. This ensures that every new form submission results in a perfectly formatted, personalized Google Document stored safely in Google Drive, significantly accelerating operational tasks. Utilizing this advanced n8n workflow demonstrates the power of custom logic paired with native n8n node capabilities.

How it Works

The entire process is initiated by an n8n trigger and proceeds through several critical data manipulation steps before finalizing the document replacement.


  1. Form Submission (n8n Trigger): The n8n workflow is activated when a user submits data to the internal n8n Form trigger (a specialized n8n node). A key component of this n8n trigger setup is ensuring security, often via Basic Authentication.

  2. Template Copying: The Google Drive n8n node then executes the 'Copy template file' operation, creating a fresh copy of the master Google Doc template. The new file is dynamically named using data from the form (e.g., {{ $json.name }}).

  3. Data Formatting (Step 1): The first Code n8n node, 'Format form data', iterates through the input received from the n8n trigger. It extracts all submitted key-value pairs into a standardized, flat array structure, preparing the data for the API.

  4. Data Formatting (Step 2): The second Code n8n node, 'Format form data to Google Doc API', transforms the standardized data into the precise JSON array format required by the Google Docs API's batchUpdate method. It structures each field replacement as an API request object, linking the form key (e.g., name) to the document placeholder ({{name}}).

  5. Data Replacement: Finally, the HTTP Request n8n node, 'Replace data in Google Doc', uses the Google Docs OAuth API credentials to send the batchUpdate request to the newly copied document. This action seamlessly replaces all templated text (e.g., {{address}}) with the corresponding data submitted via the n8n trigger form, completing the dynamic document generation process facilitated by this powerful n8n workflow.

Installation Guide

To deploy this n8n workflow and generate documents from your n8n trigger form:


  1. Import: Copy the provided n8n workflow JSON and paste it into your n8n instance using the 'New' menu -> 'Import from JSON'.

  2. Credentials Setup:

Google Drive: Configure a Google Drive OAuth2 API credential for the 'Copy template file' n8n node. Ensure the account has permission to read the template and write new files.
Google Docs: Configure a separate Google Docs OAuth2 API credential for the 'Replace data in Google Doc' n8n node. This requires permissions to modify document content.

  1. Template Setup: In the 'Copy template file' n8n node, update the File ID parameter to point to your desired Google Doc template. Ensure your template contains placeholders matching your form field names (e.g., if the form has a field name, the template must use {{name}}).

  2. Form Configuration: Configure the 'Form' n8n trigger node, adding all necessary form fields. For security, it is highly recommended to enable Basic Authentication as suggested by the sticky note.

Node Details

Form (n8n trigger): This is the entry point and n8n trigger for the entire automation.
Function: Captures user input via a simple web form interface built directly into n8n.
Key Configuration: Defines required form fields (e.g., 'name') and includes a sticky note advising the setup of Basic Auth for security.
Copy template file (Google Drive n8n node):
Function: Copies a specific Google Doc template file (identified by its ID) to create a new, unique document for the current submission.
Key Configuration: Uses an expression ={{ $json.name }} to name the new file based on the form input.
Format form data (Code n8n node):
Function: Transforms the nested JSON output from the n8n trigger into a standardized, flat array of key-value objects, making it easier to process in subsequent steps of the n8n workflow.
Format form data to Google Doc API (Code n8n node):
Function: Generates the specific replaceAllText JSON structure required by the Google Docs API. This complex transformation is crucial for mapping form data to the placeholders within the n8n templates.
Replace data in Google Doc (HTTP Request n8n node):
Function: Sends a POST request to the Google Docs batchUpdate endpoint using the specialized data payload generated by the previous Code n8n node. This executes the actual text replacement in the document.
* Key Configuration: Uses a dynamic URL based on the document ID from the 'Copy template file' node and employs the 'Predefined Credential Type' for Google Docs OAuth2 API authentication.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by
Krzysztof Kuzara
Krzysztof Kuzara

I am a backend developer with over 10 years of experience, specializing in business process automation and system integrations. I use n8n to streamline workflows, build APIs, and automate operations in companies.

Featured*