AutomationFlowsAI & RAG › Extract and Validate Invoice Data From Google Drive Using Ocr.space, Gemini,…

Extract and Validate Invoice Data From Google Drive Using Ocr.space, Gemini,…

Original n8n title: Extract and Validate Invoice Data From Google Drive Using Ocr.space, Gemini, and Google Sheets

ByWeblineIndia @weblineindia on n8n.io

This workflow monitors a Google Drive folder for newly uploaded invoice files, extracts text with OCR.Space, uses Google Gemini to convert the OCR text into structured invoice fields, validates required values, then stores results in Google Sheets and sends Gmail notifications…

Event trigger★★★★☆ complexityAI-powered17 nodesGoogle Drive TriggerGoogle DriveHTTP RequestGoogle GeminiGmailGoogle Sheets
AI & RAG Trigger: Event Nodes: 17 Complexity: ★★★★☆ AI nodes: yes Added:

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

This workflow follows the Gmail → 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": "Lnfl76S3s15AZU2h",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Intelligent Invoice Data Capture Workflow (Procurement & Finance Industry)",
  "tags": [],
  "nodes": [
    {
      "id": "a702c185-0504-44e0-8478-180759ee357d",
      "name": "Invoice Upload Trigger",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -368,
        -192
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "1M_Up8SPJyzS8njyZSUfIZb7AEwhQTV9L",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1M_Up8SPJyzS8njyZSUfIZb7AEwhQTV9L",
          "cachedResultName": "Invoice_Automation"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b17f7cfa-408e-4d84-b10b-0b938f5f8300",
      "name": "Download Invoice File",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -80,
        -192
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "a9ef724d-cf24-47d6-bd9e-0b9904959808",
      "name": "Validate Supported File Type",
      "type": "n8n-nodes-base.if",
      "position": [
        272,
        -192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "62461524-fefb-4902-94c2-47d042f63c0e",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $binary.data.mimeType }}",
              "rightValue": "pdf"
            },
            {
              "id": "3bd40f85-ddb6-4fa3-ae37-1c437b560dc1",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $binary.data.mimeType }}",
              "rightValue": "jpg"
            },
            {
              "id": "de8bbd64-7192-47b9-81f4-9dfae70a795f",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $binary.data.mimeType }}",
              "rightValue": "jpeg"
            },
            {
              "id": "e437cdc6-e647-4aa9-8094-a55ba3255bee",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $binary.data.mimeType }}",
              "rightValue": "png"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "10584a1c-e7bb-4a91-863c-1a284bb937c9",
      "name": "Extract Invoice Text (OCR)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        672,
        -208
      ],
      "parameters": {
        "url": "https://api.ocr.space/parse/image",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "K89513988988957"
            },
            {
              "name": "language",
              "value": "eng"
            },
            {
              "name": "file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            }
          ]
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "c1488a93-1f8d-4d14-93ff-f868af0ce5c0",
      "name": "Check OCR Processing Status",
      "type": "n8n-nodes-base.if",
      "position": [
        1008,
        -208
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "9b532364-fdcd-4a75-b97d-27950eb15970",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.IsErroredOnProcessing }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "2f0d5674-2c8e-4430-a291-279506dff6d0",
      "name": "AI Invoice Data Extraction",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        1376,
        -192
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-3-flash-preview"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are an AI invoice extraction assistant.\n\nExtract ALL invoice fields carefully including:\nsupplier name,\ninvoice number,\ninvoice date,\ntax amount,\ntotal amount,\ncurrency,\nand line items.\n\nRules:\n- Return ONLY valid JSON\n- No markdown\n- No explanations\n- Clean OCR mistakes if obvious\n- Keep amounts numeric\n- If value missing return empty string\n\nRequired JSON format:\n\n{\n  \"supplier_name\": \"\",\n  \"invoice_number\": \"\",\n  \"invoice_date\": \"\",\n  \"tax_amount\": \"\",\n  \"total_amount\": \"\",\n  \"currency\": \"\",\n  \"line_items\": [\n    {\n      \"item_name\": \"\",\n      \"quantity\": \"\",\n      \"price\": \"\"\n    }\n  ]\n}\n\nOCR Text:\n{{ $json[\"ParsedResults\"][0][\"ParsedText\"] }}"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e0edbc83-0aa9-453b-982f-e5f80b60d0b4",
      "name": "Validate Extracted Invoice Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1840,
        -192
      ],
      "parameters": {
        "jsCode": "const raw = JSON.parse($json.content.parts[0].text);\n\nconst validatedData = {\n  supplier_name: raw.supplier_name || \"\",\n  invoice_number: raw.invoice_number || \"\",\n  invoice_date: raw.invoice_date || \"\",\n  tax_amount: Number(raw.tax_amount || 0),\n  total_amount: Number(raw.total_amount || 0),\n  currency: raw.currency || \"INR\",\n  line_items: raw.line_items || [],\n  validation_status: \"valid\",\n  missing_fields: []\n};\n\n// Required field validation\nif (!validatedData.invoice_number) {\n  validatedData.missing_fields.push(\"invoice_number\");\n}\n\nif (!validatedData.supplier_name) {\n  validatedData.missing_fields.push(\"supplier_name\");\n}\n\nif (!validatedData.total_amount) {\n  validatedData.missing_fields.push(\"total_amount\");\n}\n\n// Set validation status\nif (validatedData.missing_fields.length > 0) {\n  validatedData.validation_status = \"manual_review\";\n}\n\nreturn [{ json: validatedData }];"
      },
      "typeVersion": 2
    },
    {
      "id": "a0d3fdab-de24-4a63-93b3-751adf6739c9",
      "name": "Check Missing Invoice Fields",
      "type": "n8n-nodes-base.if",
      "position": [
        2144,
        -192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "a7d72835-7408-45bb-9422-be4bef45a9c1",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.validation_status }}",
              "rightValue": "=manual_review"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "7e77a045-15d5-4fb2-926a-d29fbef51b15",
      "name": "Send Manual Review Alert",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2384,
        -208
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=Missing Fields:\n{{ JSON.stringify($json.missing_fields) }}\n\nInvoice Number:\n{{ $json.invoice_number }}",
        "options": {},
        "subject": "Invoice Needs Manual Review",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "6957d409-60af-4bad-b457-a9dad61a9b4c",
      "name": "Store Invoice Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2416,
        224
      ],
      "parameters": {
        "columns": {
          "value": {
            "total_amount": "={{ $json.total_amount }}",
            "supplier_name": "={{ $json.supplier_name }}",
            "invoice_number": "={{ $json.invoice_number }}",
            "validation_status": "={{ $json.validation_status }}"
          },
          "schema": [
            {
              "id": "supplier_name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "supplier_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "invoice_number",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "invoice_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "total_amount",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "total_amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "validation_status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "validation_status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1vtq9OQtSWCZBbEsLuFEfL3tn4VuHRo3sFDe16dO96oU/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1vtq9OQtSWCZBbEsLuFEfL3tn4VuHRo3sFDe16dO96oU",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1vtq9OQtSWCZBbEsLuFEfL3tn4VuHRo3sFDe16dO96oU/edit?usp=drivesdk",
          "cachedResultName": "Store_Invoice_Data"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "6079c9b2-fea2-4beb-90db-3936fbf67cc4",
      "name": "Send Processing Confirmation",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2768,
        224
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=Hello Team,\n\nA new invoice has been successfully processed and stored.\n\nSupplier Name:\n{{ $json.supplier_name }}\n\nInvoice Number:\n{{ $json.invoice_number }}\n\nInvoice Date:\n{{ $json.invoice_date }}\n\nTotal Amount:\n\u20b9{{ $json.total_amount }}\n\nValidation Status:\n{{ $json.validation_status }}\n\nThe invoice data has been stored successfully in Google Sheets.\n\nRegards,\nAI Invoice Automation Workflow\n",
        "options": {},
        "subject": "=Invoice Processed Successfully - {{ $json.invoice_number }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b7a2f2e2-fcf7-40f1-9a9d-e05b4db0f4c9",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1632,
        -576
      ],
      "parameters": {
        "width": 1008,
        "height": 1232,
        "content": "# How It Works\n### This workflow automatically processes invoice files uploaded to Google Drive. Once a PDF, JPG, or PNG invoice is uploaded, the workflow downloads the file, validates the file type, and extracts invoice text using OCR. Gemini AI then converts the extracted text into structured invoice data including supplier name, invoice number, invoice date, taxes, totals, and line items. The workflow validates the extracted data, routes incomplete invoices for manual review, stores validated invoice data in Google Sheets, and finally sends a confirmation email notification. This creates a fully automated AI-powered invoice processing system.\n\n# Setup Steps\n\n## Prepare Google Sheets\nCreate a Google Sheet with invoice fields such as supplier name, invoice number, invoice date, total amount, and validation status.\n\n## Connect Accounts in n8n\nAdd credentials for Google Drive, Google Sheets, Gmail, Gemini API, and OCR.Space API.\n\n## Add Trigger\nUse Google Drive Trigger to monitor the invoice upload folder.\n\n## Download & Validate Files\nDownload uploaded invoices and validate supported file formats like PDF, JPG, JPEG, and PNG.\n\n## Extract Invoice Text\nUse OCR.Space API through HTTP Request node to extract text from invoice files.\n\n## Extract Structured Data with AI\nUse Gemini AI node to generate structured invoice JSON data from OCR text.\n\n## Validate Invoice Data\nUse Code node and IF node to validate required invoice fields and detect missing data.\n\n## Store Invoice Data\nStore validated invoice information into Google Sheets.\n\n## Send Notifications\nSend Gmail alerts for successful processing or manual review requests."
      },
      "typeVersion": 1
    },
    {
      "id": "aa592220-0f34-4fd7-aa45-6788853830a7",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        -384
      ],
      "parameters": {
        "color": 7,
        "width": 928,
        "height": 384,
        "content": "## Invoice Intake & Validation\n\nMonitors Google Drive for new invoice uploads, downloads the file, and validates supported formats (PDF, JPG, JPEG, PNG) before processing."
      },
      "typeVersion": 1
    },
    {
      "id": "224e5142-8082-4588-ae17-52097ed15799",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 736,
        "height": 400,
        "content": "## OCR Text Extraction & Verification\n\nUses OCR.Space API to extract text from invoice documents and verifies that OCR processing completed successfully before continuing."
      },
      "typeVersion": 1
    },
    {
      "id": "b862b005-628e-438d-9d69-bba16f3fb22f",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1328,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 400,
        "content": "## AI Invoice Understanding\n\nGemini AI converts OCR text into structured invoice data, then validates required fields, amounts, supplier details, and invoice information."
      },
      "typeVersion": 1
    },
    {
      "id": "7209be21-d483-400c-8ed1-466abc6add91",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2080,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 464,
        "height": 400,
        "content": "## Manual Review Check\n**Node Used:** IF Node + Gmail Node  \nRoutes incomplete invoices for manual review and sends alert emails."
      },
      "typeVersion": 1
    },
    {
      "id": "84c9e288-7278-490e-bb53-6fbac2f5d7b5",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2288,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 736,
        "height": 368,
        "content": "## Storage & Notification\n\nStores validated invoice information in Google Sheets and sends processing confirmation emails with invoice details."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "d9521aef-3244-48ea-8113-384da6f45ec4",
  "nodeGroups": [],
  "connections": {
    "Store Invoice Data": {
      "main": [
        [
          {
            "node": "Send Processing Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Invoice File": {
      "main": [
        [
          {
            "node": "Validate Supported File Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Invoice Upload Trigger": {
      "main": [
        [
          {
            "node": "Download Invoice File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Invoice Data Extraction": {
      "main": [
        [
          {
            "node": "Validate Extracted Invoice Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Invoice Text (OCR)": {
      "main": [
        [
          {
            "node": "Check OCR Processing Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check OCR Processing Status": {
      "main": [
        [],
        [
          {
            "node": "AI Invoice Data Extraction",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Missing Invoice Fields": {
      "main": [
        [
          {
            "node": "Send Manual Review Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Store Invoice Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Supported File Type": {
      "main": [
        [
          {
            "node": "Extract Invoice Text (OCR)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Extracted Invoice Data": {
      "main": [
        [
          {
            "node": "Check Missing Invoice Fields",
            "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 monitors a Google Drive folder for newly uploaded invoice files, extracts text with OCR.Space, uses Google Gemini to convert the OCR text into structured invoice fields, validates required values, then stores results in Google Sheets and sends Gmail notifications…

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

More AI & RAG workflows → · Browse all categories →

Related workflows

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

AI & RAG

Accountants and office managers who want to automatically classify and organize documents in Google Drive.

Google Drive, HTTP Request, Google Sheets +2
AI & RAG

Arvifund - Supabase (Fixed v5). Uses httpRequest, telegram, googleSheets, telegramTrigger. Event-driven trigger; 91 nodes.

HTTP Request, Telegram, Google Sheets +9
AI & RAG

Arvifund - Supabase. Uses httpRequest, telegram, googleSheets, telegramTrigger. Event-driven trigger; 90 nodes.

HTTP Request, Telegram, Google Sheets +8
AI & RAG

Arvifund - Supabase (Fixed v2). Uses httpRequest, telegram, googleSheets, telegramTrigger. Event-driven trigger; 90 nodes.

HTTP Request, Telegram, Google Sheets +9
AI & RAG

Arvifund - Supabase (Fixed v4). Uses httpRequest, telegram, googleSheets, telegramTrigger. Event-driven trigger; 90 nodes.

HTTP Request, Telegram, Google Sheets +9