n8n tutorial - Lesson 10: Auto-Generate Google Docs from Data with n8n

Hi everyone, in this post we're building a workflow that auto-generates a Google Doc from structured data using n8n — no code, no third-party libraries. This is part of our n8n Workflow Automation Tutorial series and covers the exact pipeline from Session 10, where we built T3-B3-Doc-Generator: a 4-node workflow that copies a template, replaces placeholders, and produces a ready-to-read receipt document in Google Drive.

How to do:

Step 1 — Enable the Google Docs API in Google Cloud Console

Before n8n can write to Google Docs, the API must be active in your Google Cloud project.
  1. Go to Google Cloud Console → APIs & Services → Library.
  2. Search for Google Docs API and click Enable.
  3. Do the same for Google Drive API — both are required for this workflow.

Note — If you followed earlier sessions in this series, you already have an OAuth Client named n8n-sheets-client. You can reuse it for both Google Docs and Google Drive credentials — no need to create a new OAuth Client.

Step 2 — Create Google Docs and Google Drive Credentials in n8n

You need two separate credentials, but both reuse the same OAuth Client you set up in Week 1.
  1. In n8n, go to Credentials → New and choose Google Docs OAuth2. Name it Google Docs (Personal).
  2. Under OAuth Client, select your existing n8n-sheets-client and complete the OAuth flow.
  3. Repeat the same process: create a second credential, choose Google Drive OAuth2, name it Google Drive (Personal), and reuse n8n-sheets-client.

Tip — Reusing one OAuth Client for multiple Google service credentials is a clean pattern: fewer apps to manage in Google Cloud, and authorization is already granted. This is the "use what you already have" principle — always check existing resources before creating new ones.

Step 3 — Create the Google Doc Template with Placeholders

The template is a regular Google Doc with placeholder tokens that the workflow will replace with real data.
  1. Open Google Docs and create a new document. Name it T3-B3-Receipt-Template.
  2. Add a Heading 1 title at the top, then add six labeled fields using this placeholder syntax: <<fieldName>>.
    • Example placeholders: <<vendor>>, <<date>>, <<amount>>, <<category>>, <<payment_method>>, <<note>>.
    • Bold each label (e.g., Vendor:) and leave the placeholder value unbolded.
  3. Copy the document's ID from the URL bar — it looks like 1G7vzOxr8CX6TtbgIsd1mug0di3kZIL4CAZUClSBf_Ro. Save this for later.

Critical note — Do not use {{fieldName}} syntax in your template. n8n treats double curly braces as its own expression syntax, so the template engine will try to evaluate them and throw an error. Use <<fieldName>> instead — it has no conflict with n8n expressions.

Step 4 — Build the Workflow: Manual Trigger and Set Sample Data

Create the workflow T3-B3-Doc-Generator and add the first two nodes to simulate invoice data.
  1. In n8n, create a new workflow and name it T3-B3-Doc-Generator.
  2. Add a Manual Trigger node as the starting point — this lets you test the workflow on demand.
  3. Add an Edit Fields (Set) node. Name it Set Sample Data and define six fields:
    • vendorHighlands Coffee
    • date2026-05-08
    • amount85000
    • categoryFood & Drink
    • payment_methodMoMo
    • noteTeam coffee
  4. Connect Manual Trigger → Set Sample Data.

Tip — Using a Set node to simulate data is the standard testing pattern in n8n workflow automation. Later, when you wire this to a real Google Sheets source, you simply replace this node — the rest of the pipeline stays unchanged.

Step 5 — Add Google Drive Node to Copy the Template

Instead of writing directly into the template, you copy it first so the original stays clean for future runs.
  1. Add a Google Drive node. Set Operation to Copy File.
  2. Set File ID to your template's ID: 1G7vzOxr8CX6TtbgIsd1mug0di3kZIL4CAZUClSBf_Ro.
  3. Set the Name field to a dynamic expression:
    • Use: Receipt {{$json.vendor}} - {{$json.date}} ({{$now.toFormat("HHmmss")}})
    • The HHmmss timestamp prevents duplicate file names when you run the workflow multiple times on the same day.
  4. Set Credential to Google Drive (Personal).
  5. Connect Set Sample Data → Google Drive Copy File.

Production tip — Google Drive — unlike Windows or Linux filesystems — allows multiple files with identical names in the same folder. Without the timestamp suffix, running the workflow twice produces two files named exactly the same, which causes confusion when looking up documents. Always include a timestamp in dynamically generated file names.

Step 6 — Add Google Docs Node to Replace Placeholders

This node opens the newly copied Doc and swaps every placeholder with real data using Find & Replace.
  1. Add a Google Docs node. Set Operation to Update.
  2. Set Document ID by referencing the output of the Drive node: {{$('Google Drive').item.json.id}}.
  3. Set Credential to Google Docs (Personal).
  4. Under Actions, add six Find and Replace Text action cards — one per placeholder:
    • Card 1: Text to find = <<vendor>> | Replace with = {{$('Set Sample Data').item.json.vendor}}
    • Card 2: Text to find = <<date>> | Replace with = {{$('Set Sample Data').item.json.date}}
    • Card 3: Text to find = <<amount>> | Replace with = {{$('Set Sample Data').item.json.amount}}
    • Card 4: Text to find = <<category>> | Replace with = {{$('Set Sample Data').item.json.category}}
    • Card 5: Text to find = <<payment_method>> | Replace with = {{$('Set Sample Data').item.json.payment_method}}
    • Card 6: Text to find = <<note>> | Replace with = {{$('Set Sample Data').item.json.note}}
  5. Connect Google Drive Copy File → Google Docs Update.

Note — The expression ${'NodeName'} (with the node name in quotes) is how you reference data from any upstream node by name in n8n — not just the immediately previous one. This is especially useful when your pipeline branches or when you need to pull data from a node several steps back.

Step 7 — Test the Workflow with Two Sample Datasets

Run the workflow with different inputs to confirm the pipeline is stable and formatting is preserved.
  1. Click Execute Workflow with the Highlands Coffee data already set in Set Sample Data.
  2. Open your Google Drive and find the generated file (e.g., Receipt Highlands Coffee - 2026-05-08 (143022)). Verify all six placeholders were replaced and that Heading 1 formatting and bold labels are intact.
  3. Go back to Set Sample Data and change the values to a second test case:
    • vendorGrab
    • date2026-05-06
    • amount52000
    • categoryTransport
    • payment_methodGrabPay
    • noteRide to office
  4. Execute again and verify the second Doc is created with a different timestamp in its name and all correct values.

Tip — Testing with at least two different datasets is a good habit in n8n google docs automation work. One test confirms it works; two tests confirm the pattern is stable and not dependent on a specific value.

Key Lessons from This Session

  1. Use <<placeholder>> syntax in Google Doc templates, never {{placeholder}}. Double curly braces conflict with n8n's own expression engine and will cause errors at runtime.
  2. Always check what credentials you already have before creating new ones. Reusing an existing OAuth Client (like n8n-sheets-client) for Google Docs and Google Drive saves setup time and keeps your Google Cloud project clean.
  3. Add a timestamp to dynamically generated file names. Google Drive allows duplicate file names — a $now.toFormat("HHmmss") suffix ensures every run produces a uniquely identifiable file.
  4. Copy the template first, then replace placeholders in the copy. Writing directly into the template would destroy it; the Drive Copy File step preserves the original for every future run.
  5. Reference upstream nodes by name using ${'NodeName'}. This lets the Google Docs node pull data from the Set Sample Data node even though they are not directly connected.
  6. List all available options before recommending one. The initial oversight of omitting Google Docs API in favor of Pandoc/docxtemplater/docx-js led to unnecessary complexity — a reminder to evaluate all tools at hand first.

Conclusion:

In this session of our n8n tutorial series, you built a complete 4-node pipeline — Manual Trigger → Set Data → Drive Copy → Docs Update — that auto-generates a formatted Google Doc from structured data without any code. The key insight is that Google Docs' Find & Replace API, combined with n8n's built-in Google Docs node and a clean placeholder convention, gives you a production-ready document generator in under two hours. In the next session, we'll scale this up into a full weekly report workflow: pulling rows from Google Sheets, generating AI-written insights, and saving the final report to a dedicated Drive folder with a Telegram notification.

If you have any questions, feel free to leave a comment below. Thank you!

Tags: n8n google docs automation, n8n tutorial, n8n workflow automation, google docs api n8n, auto generate google docs, n8n google drive, document automation n8n, n8n beginner tutorial

Maybe you are interested!