Advanced Automation: Creating Conditional Invoices with n8n and Google Sheets
This guide is a follow-up to our basic article, "How to integrate PDF Generator API with n8n". While the first article covered the fundamentals of generating a document, this tutorial will teach you how to build a "smart" workflow.
Our Goal: To create an automated system that:
- Triggers when a new row is added to a Google Sheet.
- Intelligently chooses between two different PDF templates based on the data in the row.
- Generates the correct invoice as a PDF.
- Emails the invoice to the customer.
- Saves a copy of the invoice to a specific Google Drive folder.
Prerequisites
Before you begin, please ensure you have the following ready:
- A working n8n instance: This workflow runs perfectly on both n8n cloud and a local setup.
- PDF Generator API Account: You will need at least two different invoice templates created in your account (e.g., a "Standard Invoice" and a "Pro Invoice").
- Google Account Credentials: You must have credentials for Google Sheets, Gmail, and Google Drive connected to your n8n instance. Remember to create separate credentials for each Google service.
- A Google Sheet: This will be our data source. Create a new sheet with (minimum) columns like
Customer_Name
,Email
,Invoice_Number
, andType
.
Step 1: The Foundation - Preparing Your Data
The key to this entire workflow is the "trigger" column in your Google Sheet. For this example, we'll use the Type
column. This column will contain either the word "Standard" or "Pro" to tell n8n which template to use.
Step 2: Building the Workflow - Trigger and Logic
Node 1: Google Sheets Trigger
- Add a Google Sheets node to your canvas.
- Configure it to trigger On Row Added and point it to the sheet you just created.
- Run a test to ensure it correctly pulls data from your sheet.
Node 2: The IF Node (The Brain) This is where the magic happens. The IF node will direct the workflow based on our data.
- Add an IF node and connect it to the Google Sheets trigger.
- Set up a condition to check the value from our
Type
column. - Condition:
{{ $json["Type"] }}
|is equal to
|Pro
This creates two output paths: true
(if the type is "Pro") and false
(for everything else, which we'll treat as "Standard").
Step 3: Generating the Correct PDF
Now we'll use our two branches to generate the appropriate document. For detailed guide on how to setup our PDF Generator API Nodes please follow this article.
- On the
true
path: - Add a PDF Generator API node.
- Configure it to use your "Pro Invoice" template.
- Map the data from the Google Sheets node to your template's fields.
- On the
false
path: - Add another PDF Generator API node.
- Configure it to use your "Standard Invoice" template.
- Map the data just as you did for the "Pro" version.
Step 4: Handling the Output - The Merge Node
- Add a Merge node to your canvas.
- Connect the outputs of your PDF Generator API nodes to Input 1 & 2.
- Configure the Merge Node:
- Mode:
Append
- Number of inputs:
2
- Mode:
Step 5: Sending and Archiving the Invoice
With our data correctly merged, the final steps are easy.
Node 3: Gmail (Send a message)
- Add a Gmail node and connect the Merge node to it.
- To: Use an expression to pull the email from the sheet data:
{{ $('Google Sheets Trigger').item.json.Email }}
- Attachments: In the attachments field, specify the name of the property that holds your binary file
{{ $json.filename }}
.
Node 4: Google Drive (Upload file)
- Add a Google Drive node.
- Select Parent Drive & Folder.
- File Name: Create a dynamic name, e.g.,
{{ $('Google Sheets Trigger').item.json.Type }}_Invoice_{{ $('Google Sheets Trigger').item.json.Invoice_Number }}
- Input Field Name: Specify the property holding the file. This should be
{{ $json.filename }}
.
Related articles you may find helpful
- How to embed editor to my application?
- How to share templates with other workspaces?
- How to use the editor?
Updated on: 13/10/2025
Thank you!