Why Automate Invoicing with n8n?
Manual invoicing is time-consuming and prone to errors. By using n8n, you can create a seamless billing workflow that pulls data from Google Sheets, generates professional invoices, emails them to clients, and follows up with automated payment reminders until the invoice is settled. This not only saves hours each month but also improves cash flow and reduces late payments.
Prerequisites
Before you start, ensure you have:
- An n8n instance (self-hosted or cloud) with access to HTTP Request, Google Sheets, Email (SMTP), and Schedule nodes.
- A Google Sheet with columns: Client Name, Email, Amount, Due Date, Invoice Number, Status (e.g., Pending, Paid).
- SMTP credentials for sending emails (e.g., Gmail SMTP or a transactional email service).
- Basic familiarity with n8n's node-based interface.
Step 1: Set Up the Schedule Trigger
Start with a Schedule node to run your workflow daily (or at your preferred frequency). Configure it to trigger at a specific time, such as every morning at 9 AM. This ensures invoices and reminders are sent consistently.
Step 2: Fetch Data from Google Sheets
Add a Google Sheets node to read rows from your invoice sheet. Connect it to the Schedule node. Configure the node with:
- Authentication: Use a service account or OAuth2 with access to your sheet.
- Operation: Get rows (or Get all rows).
- Document ID: Your Google Sheet ID.
- Sheet name: The name of your sheet (e.g., “Invoices”).
This will output an array of objects, each representing a row. You can then filter rows where Status is “Pending” and the due date has passed or is today.
Step 3: Filter Pending Invoices
Use a Filter node (or Function node) to keep only rows where Status equals “Pending”. Optionally, you can also check if the current date is on or after the due date to send reminders. The filtered data will be passed to the next steps.
Step 4: Generate Invoice Content
For each pending invoice, you need to create an invoice document. You have two options:
Option A: Use an HTML Template
Create a Function node that builds an HTML invoice string using the row data. For example:
const items = $input.all();
return items.map(item => {
const row = item.json;
const html = `
<h2>Invoice #${row.InvoiceNumber}</h2>
<p>Client: ${row.ClientName}</p>
<p>Amount Due: $${row.Amount}</p>
<p>Due Date: ${row.DueDate}</p>
<hr>
<p>Please make payment by the due date.</p>
`;
return { ...item.json, invoiceHtml: html };
});Option B: Use a PDF Generation Service
If you prefer PDF invoices, use an HTTP Request node to call a PDF generation API (like PDF.co or Gotenberg) with the HTML template. For simplicity, this guide uses HTML in the email body.
Step 5: Send the Invoice via Email
Add an Email (SMTP) node to send the invoice. Configure it with:
- SMTP credentials (host, port, user, password).
- From: Your email address.
- To: Client email from the row.
- Subject: “Invoice #{{InvoiceNumber}} from [Your Company]”.
- Body type: HTML.
- Body: The invoice HTML generated in the previous step.
You can also attach a PDF if you generated one. To avoid sending duplicate invoices, update the Google Sheet status to “Sent” after sending. Use a Google Sheets node with operation “Update Row” to set Status to “Sent” for the processed row.
Step 6: Automate Payment Reminders
To follow up on unpaid invoices, you need to track when the invoice was sent and send reminders at intervals. One approach:
- Add a column “SentDate” to your sheet and record the date when the invoice is first sent.
- In your daily workflow, after fetching all rows, filter rows where Status is “Sent” and the current date is more than 7 days after SentDate (or your chosen interval).
- Send a reminder email with a polite message and a link to pay (if you have a payment portal).
- Optionally, increment a “ReminderCount” column and update it each time.
You can also escalate reminders: after 14 days, send a more urgent email, and after 21 days, notify your finance team via Slack or email.
Step 7: Handle Payment Confirmation
When a client pays, you need to update the sheet. You can set up a separate webhook workflow that listens for payment notifications from your payment gateway (e.g., Stripe, PayPal). The webhook receives payment data, matches it to the invoice number, and updates the Status to “Paid” along with the payment date. This stops further reminders.
Full Workflow Overview
- Schedule Trigger (daily at 9 AM)
- Google Sheets – Get all rows
- Filter – Keep rows where Status is “Pending” or “Sent”
- Switch – Branch based on Status:
- If “Pending”: Generate invoice, send email, update Status to “Sent” and set SentDate to today.
- If “Sent”: Check if reminder is due (e.g., 7 days after SentDate). If yes, send reminder, increment ReminderCount.
- Update Google Sheets – Update Status, SentDate, ReminderCount as needed.
Best Practices for n8n Invoice Automation
- Use error handling: Add Error Trigger nodes to catch failures and notify you (e.g., via email or Slack).
- Test with sample data: Run the workflow on a test sheet before going live.
- Secure credentials: Store SMTP passwords and API keys in n8n’s credential system.
- Monitor performance: If you have many invoices, consider batching or using pagination.
- Comply with regulations: Ensure your emails include an unsubscribe option and comply with anti-spam laws.
Conclusion
With n8n, you can build a powerful invoice automation workflow that saves time, reduces errors, and improves payment collection. By integrating Google Sheets, email, and optional payment gateways, you create a seamless billing process that runs on autopilot. Start small, iterate, and enjoy the benefits of automated invoicing.