Generate Invoices, Save to Drive and Send Email to Customer with JS + G Sheets
Last edited 11 days ago
This workflow automates invoice generation from form submissions, ensuring unique order IDs, creating PDF invoices, storing files, emailing customers, and logging invoice data — all seamlessly integrated.
🔹 Workflow Overview
-
Trigger (Webhook) Starts when an order form is submitted, capturing customer and order details.
-
Generate Random Order ID A Function node creates a unique alphanumeric invoice ID (e.g.,
INV-X92B7D
). -
Check for Duplicate Order ID Google Sheets looks up the generated order ID in your invoice log sheet to prevent duplicates.
-
Conditional Check (IF Node)
- If the ID already exists → regenerates a new ID (loops back)
- If unique → proceeds to invoice creation
-
Prepare Invoice Data A Set node formats customer info, date, order items, and the unique order ID to fit your invoice template.
-
Convert HTML to PDF HTTP Request node sends your invoice HTML to the RapidAPI HTML-to-PDF service and receives the PDF file.
-
Upload PDF to Cloud Storage Save the PDF in Google Drive or Dropbox with a clear file name like
Invoice-INV-X92B7D.pdf
. -
Send Invoice Email to Customer Email node attaches the PDF and includes the order ID in the email subject/body.
-
Log Invoice Details Append invoice data (customer info, order ID, total, PDF link) to your Google Sheet for tracking.
⚙️ Node Details & Setup
1. Webhook Trigger
- Configure to receive form submissions (order details like name, email, items, total).
2. Function: Generate Random Order ID
- Sample JS code generates unique IDs prefixed by
INV-
.
3. Google Sheets: Lookup Row
- Set up connection to your invoice log sheet.
- Search for existing order ID to avoid duplicates.
4. IF Node: Check Order ID Existence
- Condition: If order ID found → loop to regenerate.
- Else → continue workflow.
5. Set Node: Prepare Invoice HTML
- Define variables like customer name, date, items, and order ID.
- This data populates your HTML invoice template.
6. HTTP Request: Convert HTML to PDF
- API URL to get your key
- Send invoice HTML in the request body.
- Receive PDF file blob or download URL.
7. Google Drive (or Dropbox) Upload
- Upload the PDF file.
- Use file name format:
Invoice-{{$json["order_id"]}}.pdf
8. Email Node
- Recipient: customer email from the form data.
- Attach generated PDF.
- Include order ID in email subject or body for reference.
9. Google Sheets: Append Row
- Log invoice metadata to keep records updated.
📁 Google Sheets Template
You can make a copy of the invoice log template here
This sheet includes columns for order\_id, customer name, email, total, and invoice PDF link. Customize it as needed.
📌 Additional Notes
- Customize the invoice HTML template inside the Set node to match your branding.
- Ensure API credentials for RapidAPI, Google Drive/Dropbox, and email are properly set up in your n8n credentials.
- You can expand this workflow by adding payment processing or SMS notifications.
Need help or want a custom workflow?
Reach out via email at joseph@uppfy.com.
You may also like
New to n8n?
Need help building new n8n workflows? Process automation for you or your company will save you time and money, and it's completely free!