AutomationFlowsData & Sheets › Generate Invoices, Save to Drive and Send Email to Customer with Js + G Sheets

Generate Invoices, Save to Drive and Send Email to Customer with Js + G Sheets

ByJoseph @mjomba on n8n.io

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. Trigger (Webhook) Starts when an order form is submitted, capturing…

Webhook trigger★★★★☆ complexity12 nodesGoogle SheetsHTTP RequestGoogle DriveEmail Send
Data & Sheets Trigger: Webhook Nodes: 12 Complexity: ★★★★☆ Added:

This workflow corresponds to n8n.io template #4105 — we link there as the canonical source.

This workflow follows the Emailsend → Google Drive recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "K4XpJbwBJYnDiYkF",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Generate Invoices",
  "tags": [],
  "nodes": [
    {
      "id": "e56cbf88-1e0d-4dd7-a269-091ad2ce8420",
      "name": "Webhook Simulator",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -240,
        20
      ],
      "parameters": {
        "path": "7f884a07-861e-49da-bb0e-1ac6ca40ea00",
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "b01307f7-b5cb-421e-833a-0889925bb09c",
      "name": "Generate Invoice ID",
      "type": "n8n-nodes-base.code",
      "position": [
        -20,
        20
      ],
      "parameters": {
        "jsCode": "function generateOrderID(length = 6) {\n  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';\n  let result = 'INV-';\n  for (let i = 0; i < length; i++) {\n    result += chars.charAt(Math.floor(Math.random() * chars.length));\n  }\n  return result;\n}\n\nreturn [\n  {\n    json: {\n      order_id: generateOrderID()\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "bf50ca10-4021-4e6f-9c08-56fd84ce13ed",
      "name": "Check if ID Already Exists",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        200,
        20
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.order_id }}",
              "lookupColumn": "Invoice ID"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1QW_YOUR_AWS_SECRET_KEY_HERE/edit#gid=0",
          "cachedResultName": "Invoices"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1QW_YOUR_AWS_SECRET_KEY_HERE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1QW_YOUR_AWS_SECRET_KEY_HERE/edit?usp=drivesdk",
          "cachedResultName": "Uppfy Shop Invoices"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5,
      "alwaysOutputData": true
    },
    {
      "id": "c63871fa-ca0f-4069-ac0d-422d39018a9e",
      "name": "If Does not Exist",
      "type": "n8n-nodes-base.if",
      "position": [
        420,
        20
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cee7659a-cea3-494a-b4f3-c76d035a3a32",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              },
              "leftValue": "={{ $json.row_number }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "feb9ed84-a62c-4cec-bf36-b53a76711bcd",
      "name": "Set Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        740,
        -140
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1bd457b4-2c15-433a-96b3-5fabb8566866",
              "name": "order_id",
              "type": "string",
              "value": "={{ $('Generate Invoice ID').item.json.order_id }}"
            },
            {
              "id": "15c51334-b127-485e-9be4-051b086d74b2",
              "name": "customer_name",
              "type": "string",
              "value": "={{ $('Webhook Simulator').item.json.customer_name }}"
            },
            {
              "id": "8c4f2d5c-09c8-4b8c-a77f-ab3c1d752c13",
              "name": "customer_email",
              "type": "string",
              "value": "={{ $('Webhook Simulator').item.json.customer_email }}"
            },
            {
              "id": "ea1bbfe4-c12d-450f-9bee-fff8710eed42",
              "name": "products",
              "type": "array",
              "value": "={{ $('Webhook Simulator').item.json.products }}"
            },
            {
              "id": "025d0783-7eb0-4ac4-b373-39f744692cfd",
              "name": "total",
              "type": "number",
              "value": "={{ $('Webhook Simulator').item.json.total }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "0532fa4b-cdd9-4857-8701-6a5baf48fd7c",
      "name": "Create Invoice HTML",
      "type": "n8n-nodes-base.code",
      "position": [
        740,
        100
      ],
      "parameters": {
        "jsCode": "const { order_id, customer_name, customer_email, products, total } = $json;\n\n// Format products table rows\nconst productRows = products.map((item, index) => {\n  const subtotal = item.quantity * item.price;\n  return `\n    <tr>\n      <td style=\"padding: 8px; border: 1px solid #ccc;\">${index + 1}</td>\n      <td style=\"padding: 8px; border: 1px solid #ccc;\">${item.name}</td>\n      <td style=\"padding: 8px; border: 1px solid #ccc;\">${item.quantity}</td>\n      <td style=\"padding: 8px; border: 1px solid #ccc;\">$${item.price.toFixed(2)}</td>\n      <td style=\"padding: 8px; border: 1px solid #ccc;\">$${subtotal.toFixed(2)}</td>\n    </tr>\n  `;\n}).join('');\n\nconst html = `\n<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <title>Invoice ${order_id}</title>\n</head>\n<body style=\"font-family: Arial, sans-serif; color: #333; max-width: 700px; margin: auto; padding: 20px; border: 1px solid #ddd;\">\n  <h2 style=\"text-align: center;\">Invoice</h2>\n  <p><strong>Order ID:</strong> ${order_id}</p>\n  <p><strong>Customer Name:</strong> ${customer_name}</p>\n  <p><strong>Email:</strong> ${customer_email}</p>\n\n  <table style=\"width: 100%; border-collapse: collapse; margin-top: 20px;\">\n    <thead>\n      <tr>\n        <th style=\"padding: 8px; border: 1px solid #ccc;\">#</th>\n        <th style=\"padding: 8px; border: 1px solid #ccc;\">Product</th>\n        <th style=\"padding: 8px; border: 1px solid #ccc;\">Qty</th>\n        <th style=\"padding: 8px; border: 1px solid #ccc;\">Unit Price</th>\n        <th style=\"padding: 8px; border: 1px solid #ccc;\">Subtotal</th>\n      </tr>\n    </thead>\n    <tbody>\n      ${productRows}\n    </tbody>\n    <tfoot>\n      <tr>\n        <td colspan=\"4\" style=\"text-align: right; padding: 8px; border: 1px solid #ccc;\"><strong>Total:</strong></td>\n        <td style=\"padding: 8px; border: 1px solid #ccc;\"><strong>$${total.toFixed(2)}</strong></td>\n      </tr>\n    </tfoot>\n  </table>\n\n  <p style=\"margin-top: 40px; text-align: center;\">Thank you for your order!</p>\n</body>\n</html>\n`;\n\nreturn [\n  {\n    json: {\n      html\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "5a3adb6a-9f64-477e-9622-3d2b9ef2e6de",
      "name": "HTML to PDF",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -20,
        320
      ],
      "parameters": {
        "url": "https://html2pdf2.p.rapidapi.com/html2pdf",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "html",
              "value": "={{ $json.html }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "x-rapidapi-host",
              "value": "html2pdf2.p.rapidapi.com"
            },
            {
              "name": "x-rapidapi-key",
              "value": "\"your_rapid_api_key\""
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "cebf6d0d-d43f-4e50-abc0-79ff8da1817a",
      "name": "Upload PDF to GDrive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        420,
        320
      ],
      "parameters": {
        "name": "={{ $('Set Fields').item.json.order_id }} - {{ $('Set Fields').item.json.customer_name }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "b181eddc-e786-4d44-a334-e1b581b3981f",
      "name": "Email Invoice to Customer",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        640,
        320
      ],
      "parameters": {
        "html": "=Hello  {{ $('Set Fields').item.json.customer_name }},\n\nPlease pay this invoice\n\n\n{{ $('Create Invoice HTML').item.json.html }}\n\n\n<!DOCTYPE html>\n<html>\n<head>\n    <style>\n        .button {\n            display: inline-block;\n            background-color: #4CAF50;\n            border: none;\n            border-radius: 4px;\n            color: white;\n            padding: 15px 32px;\n            text-align: center;\n            text-decoration: none;\n            font-size: 16px;\n            font-weight: bold;\n            margin: 4px 2px;\n            cursor: pointer;\n            font-family: Arial, sans-serif;\n        }\n    </style>\n</head>\n<body>\n    <div style=\"text-align: center;\">\n        <a href=\"YOUR_PAYMENT_LINK_HERE\" class=\"button\">Pay Now</a>\n    </div>\n</body>\n</html>\n\n",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ $('Set Fields').item.json.order_id }} - New Invoice from Uppfy Shop ",
        "toEmail": "={{ $('Set Fields').item.json.customer_email }}",
        "fromEmail": "Uppfy Shop <your_from_email>"
      },
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "883e32b6-a812-44c8-b525-97e819af90bd",
      "name": "Append Details to Invoices Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        860,
        320
      ],
      "parameters": {
        "columns": {
          "value": {
            "Status": "Unpaid",
            "Invoice ID": "={{ $('Set Fields').item.json.order_id }}",
            "Invoice URL": "={{ $('Upload PDF to GDrive').item.json.webViewLink }}",
            "Invoice Amt.": "=${{ $('Set Fields').item.json.total }}",
            "Customer Name": "={{ $('Set Fields').item.json.customer_name }}",
            "Customer Email": "={{ $('Set Fields').item.json.customer_email }}"
          },
          "schema": [
            {
              "id": "Invoice ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Invoice ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Customer Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Customer Email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Invoice Amt.",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Invoice Amt.",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Invoice URL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Invoice URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Invoice ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1QW_YOUR_AWS_SECRET_KEY_HERE/edit#gid=0",
          "cachedResultName": "Invoices"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1QW_YOUR_AWS_SECRET_KEY_HERE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1QW_YOUR_AWS_SECRET_KEY_HERE/edit?usp=drivesdk",
          "cachedResultName": "Uppfy Shop Invoices"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "cd06d6c9-903d-4af8-8327-eb36ba3bc73a",
      "name": "Download PDF from API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        200,
        320
      ],
      "parameters": {
        "url": " https://rhodium-tecnologia-html2pdf.s3.amazonaws.com/public/pdfs/1747392997249.pdf",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "7d308e22-9b2d-4993-8aad-cc701303d38d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -280,
        -160
      ],
      "parameters": {
        "width": 180,
        "height": 320,
        "content": "## Pinned Data to Simulate Webhook Query"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "dec45f2b-cb36-4f86-a8cc-d3c498ae7aa2",
  "connections": {
    "Set Fields": {
      "main": [
        [
          {
            "node": "Create Invoice HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML to PDF": {
      "main": [
        [
          {
            "node": "Download PDF from API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Does not Exist": {
      "main": [
        [
          {
            "node": "Set Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Invoice ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook Simulator": {
      "main": [
        [
          {
            "node": "Generate Invoice ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Invoice HTML": {
      "main": [
        [
          {
            "node": "HTML to PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Invoice ID": {
      "main": [
        [
          {
            "node": "Check if ID Already Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload PDF to GDrive": {
      "main": [
        [
          {
            "node": "Email Invoice to Customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download PDF from API": {
      "main": [
        [
          {
            "node": "Upload PDF to GDrive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Invoice to Customer": {
      "main": [
        [
          {
            "node": "Append Details to Invoices Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if ID Already Exists": {
      "main": [
        [
          {
            "node": "If Does not Exist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

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. Trigger (Webhook) Starts when an order form is submitted, capturing…

Source: https://n8n.io/workflows/4105/ — original creator credit. Request a take-down →

More Data & Sheets workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Data & Sheets

Convalidaciones Académicas - Estructura Base. Uses googleSheets, emailSend, googleDrive, httpRequest. Webhook trigger; 35 nodes.

Google Sheets, Email Send, Google Drive +2
Data & Sheets

Transform your n8n instance management with this advanced automation system featuring artificial intelligence-driven workflow selection. This template provides comprehensive maintenance operations wit

n8n, HTTP Request, Google Sheets +1
Data & Sheets

Are you tired of manually entering open house visitor information into your CRM? Losing hot leads because you didn't follow up fast enough? This powerful n8n workflow automatically syncs every SignSna

Email Send, Google Sheets, HubSpot +3
Data & Sheets

TrackCollect. Uses googleSheets, httpRequest, @n-octo-n/n8n-nodes-json-database, moveBinaryData. Webhook trigger; 31 nodes.

Google Sheets, HTTP Request, @N Octo N/N8N Nodes Json Database +2
Data & Sheets

This workflow automatically saves files received via LINE Messaging API into Google Drive and logs the file details into a Google Sheet. It checks the file type against allowed types, organizes files

Google Sheets, Google Drive, HTTP Request