{
  "nodes": [
    {
      "id": "59b4e37b-f52f-415a-bb6f-7a249984ec3a",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        3280,
        840
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "d9d53795-da16-4921-9c50-a4ce036b564f",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        3500,
        840
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"invoice_number\": \"\",\n  \"invoice_date\": \"\",\n  \"due_date\": \"\",\n  \"vendor_name\": \"\",\n  \"total_amount\": \"\",\n  \"currency\": \"\",\n  \"items\": [\n    {\n      \"description\": \"\",\n      \"amount\": \"\"\n    }\n  ],\n  \"tax\": \"\",\n  \"category\": \"\"\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "69406dc2-fb14-40bd-a24b-5fa28aaa338c",
      "name": "Invoice Folder Monitor",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        2620,
        420
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "id",
          "value": "1KJ4fvXcKVMGJunsKvPYf8PkX5K9SVwFk"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ab3bbd35-7d81-482e-a9f6-242c7b98cd49",
      "name": "Download Invoice PDF",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2820,
        420
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "fc5a0c82-a1e9-468d-a2a5-0f8e7291f1d9",
      "name": "Invoice Parser AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3300,
        640
      ],
      "parameters": {
        "text": "=You are an intelligent invoice parser. I will give you raw text extracted from a PDF invoice. \n\n========================\nSTART OF RAW INVOICE TEXT\n\n{{ $json.text }}\n\nEND OF RAW INVOICE TEXT\n========================\n\nYour job is to:\n\n1. Extract key information from the invoice such as:\n   - invoice_number\n   - invoice_date\n   - due_date (if available)\n   - vendor_name\n   - total_amount\n   - currency (e.g., USD, IDR, etc.)\n   - items (as a list of item descriptions and their amounts)\n   - tax (if available)\n\n2. Detect the invoice **category**, such as:\n   - Utilities\n   - Office Supplies\n   - Travel\n   - Software\n   - Food & Beverage\n   - Others (if unknown)\n\n3. Return the result in this exact JSON format:\n\n```json\n{\n  \"invoice_number\": \"\",\n  \"invoice_date\": \"\",\n  \"due_date\": \"\",\n  \"vendor_name\": \"\",\n  \"total_amount\": \"\",\n  \"currency\": \"\",\n  \"items\": [\n    {\n      \"description\": \"\",\n      \"amount\": \"\"\n    }\n  ],\n  \"tax\": \"\",\n  \"category\": \"\"\n}\n",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "bb0a4401-9feb-4240-a62f-ad90c6c642a1",
      "name": "Insert Invoice Data",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        4180,
        640
      ],
      "parameters": {
        "columns": {
          "value": {
            "Tax": "={{ $('Invoice Parser AI Agent').item.json.output.tax }}",
            "Items": "={{ $('Invoice Parser AI Agent').item.json.output.items }}",
            "Approved": "={{ $json.data['Approve Invoice?'] }}",
            "Category": "={{ $('Invoice Parser AI Agent').item.json.output.category }}",
            "Currency": "={{ $('Invoice Parser AI Agent').item.json.output.currency }}",
            "Due Date": "={{ $('Invoice Parser AI Agent').item.json.output.due_date }}",
            "Reviewed By": "={{ $json.data['Reviewed By'] }}",
            "Vendor Name": "={{ $('Invoice Parser AI Agent').item.json.output.vendor_name }}",
            "Invoice Date": "={{ $('Invoice Parser AI Agent').item.json.output.invoice_date }}",
            "Total Amount": "={{ $('Invoice Parser AI Agent').item.json.output.total_amount }}",
            "Approval Notes": "={{ $json.data['Approval Notes'] }}",
            "Invoice Number": "={{ $('Invoice Parser AI Agent').item.json.output.invoice_number }}"
          },
          "schema": [
            {
              "id": "Invoice Number",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Invoice Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Invoice Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Invoice Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Due Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Due Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Vendor Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Vendor Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total Amount",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Total Amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Currency",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Currency",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Items",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Items",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Tax",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Tax",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Category",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Approved",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Approved",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Approval Notes",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Approval Notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Reviewed By",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Reviewed By",
              "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/1ueJfN5dFTXY3_AdvnYUL5_RjV9YwSFvbxwA_ivtqnJk/edit#gid=0",
          "cachedResultName": "Invoices"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1ueJfN5dFTXY3_AdvnYUL5_RjV9YwSFvbxwA_ivtqnJk",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ueJfN5dFTXY3_AdvnYUL5_RjV9YwSFvbxwA_ivtqnJk/edit?usp=drivesdk",
          "cachedResultName": "Copy of PDF Invoice Parser - n8n template"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "d1980b52-aa0a-479b-892f-9e81abfb35f6",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2260,
        420
      ],
      "parameters": {
        "color": 4,
        "width": 280,
        "height": 600,
        "content": "## SETUP REQUIRED\n**Author:** [Billy Christi](https://n8n.io/creators/billy/)\n\n**Copy the Google Sheet template here**:  \n\ud83d\udc49 [PDF Invoice Parser with Approval Workflow \u2013 Google Sheet Template](https://docs.google.com/spreadsheets/d/1ueJfN5dFTXY3_AdvnYUL5_RjV9YwSFvbxwA_ivtqnJk/edit?gid=0#gid=0)\n\nGoogle Sheets Structure:\nSheet: \"Invoices\"\n\u2022 Column A: Invoice Number  \n\u2022 Column B: Invoice Date  \n\u2022 Column C: Due Date  \n\u2022 Column D: Vendor Name  \n\u2022 Column E: Total Amount  \n\u2022 Column F: Currency  \n\u2022 Column G: Items  \n\u2022 Column H: Tax  \n\u2022 Column I: Category  \n\u2022 Column J: Approved\n\u2022 Column K: Approval Notes\n\u2022 Column L: Reviewed By\n\nRequired Credentials:\n\u2022 Google Drive Credential  \n\u2022 Gmail Credential \n\u2022 Google Sheets Credential \n\u2022 OpenAI API Key (GPT-4)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "858e3989-352d-4d73-a299-394b73780d59",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2600,
        1060
      ],
      "parameters": {
        "color": 5,
        "width": 700,
        "height": 560,
        "content": "## \ud83e\uddfe Automated PDF Invoice Processing & Approval Flow using OpenAI and Google Sheets\n\nWhat This Template Does:\n\n- Monitors **Google Drive**, **Gmail**, and a **web form** for incoming PDF invoices  \n- Automatically downloads and extracts raw text from PDF attachments  \n- Uses **GPT-4o-mini** to intelligently parse invoice data (invoice number, vendor, date, amount, tax, items, etc.)  \n- Categorizes invoices into types such as *Utilities, Travel, Office Supplies, Food & Beverage, Others*  \n- Sends a dynamic **approval request email** with an embedded decision form (Yes/No, reviewer name, notes)  \n- Stores both approved and rejected invoice data into **Google Sheets** for recordkeeping  \n- Sends rejection notifications to the finance team for follow-up  \n- Provides a complete, automated approval pipeline with human oversight  \n- Includes a structured JSON schema for consistent and error-free AI output  \n- Polls input sources every minute to ensure timely and responsive processing  \n- Ideal for businesses seeking to **automate their invoice approval and bookkeeping workflows** with AI\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9fa12368-2a78-4a94-9eec-4fcbfe2f0254",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3340,
        1060
      ],
      "parameters": {
        "color": 5,
        "width": 620,
        "height": 620,
        "content": "## \ud83d\udccb WORKFLOW PROCESS OVERVIEW\n\n1. **Invoice Collection**  \nInvoices are captured through three triggers: new PDFs in a Google Drive folder, incoming Gmail messages with PDF attachments, or direct uploads via a web form.\n\n2. **File Handling**  \nIf uploaded via Drive, the PDF is downloaded using its file ID; if via Gmail or form, the PDF is already available as binary data.\n\n3. **Text Extraction**  \nThe system extracts raw text from the PDF using the appropriate method based on its source (Drive, Email, or Form).\n\n4. **AI Data Parsing**  \nGPT-4 processes the extracted text into structured JSON, identifying invoice details like vendor, date, amount, and categorizing the invoice.\n\n5. **Approval Request**  \nAn email is sent to the reviewer with an approval form asking for a Yes/No decision along with optional notes.\n\n6. **Decision Routing**  \nIf approved, the data moves forward for storage; if rejected, a notification is sent to the finance team.\n\n7. **Save Invoice Data**  \nAll extracted and reviewed invoice data is saved into a Google Sheet, maintaining a full record of each invoice and its status.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "0aeca259-2a98-48c3-a892-94bf7eac802a",
      "name": "Send Invoice for Approval",
      "type": "n8n-nodes-base.gmail",
      "position": [
        3640,
        640
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=A new invoice has been submitted and requires your review and approval:",
        "options": {},
        "subject": "=[Action Required] Invoice Approval Request \u2013 {{ $json.output.vendor_name }}",
        "operation": "sendAndWait",
        "formFields": {
          "values": [
            {
              "fieldType": "dropdown",
              "fieldLabel": "Approve Invoice?",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Yes"
                  },
                  {
                    "option": "No"
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldLabel": "Reviewed By",
              "requiredField": true
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "Approval Notes"
            }
          ]
        },
        "responseType": "customForm"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "2224840e-b38b-4375-9726-4355db099d6c",
      "name": "Monitor Email Attachments",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        2820,
        640
      ],
      "parameters": {
        "simple": false,
        "filters": {},
        "options": {
          "downloadAttachments": true,
          "dataPropertyAttachmentsPrefixName": "attachment_"
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f4ff8acd-d3a0-45c4-89eb-5d32c2311cf0",
      "name": "Upload Invoice (PDF) Form",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        2820,
        840
      ],
      "parameters": {
        "options": {},
        "formTitle": "Upload Invoice (PDF)",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "Upload",
              "multipleFiles": false,
              "requiredField": true,
              "acceptFileTypes": ".pdf"
            }
          ]
        },
        "formDescription": "Upload your invoice PDF using this form."
      },
      "typeVersion": 2.2
    },
    {
      "id": "c2c7545e-344e-480d-8ff7-c14a275460cb",
      "name": "Extract Text from Drive PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3020,
        420
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "51b5bedc-ac31-4e31-a854-89d63c8fe410",
      "name": "Extract Text from Email PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3020,
        640
      ],
      "parameters": {
        "options": {},
        "operation": "pdf",
        "binaryPropertyName": "attachment_0"
      },
      "typeVersion": 1
    },
    {
      "id": "aca28461-3f7b-4530-aaec-a61bb402895b",
      "name": "Extract Text from Form PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3020,
        840
      ],
      "parameters": {
        "options": {},
        "operation": "pdf",
        "binaryPropertyName": "Upload"
      },
      "typeVersion": 1
    },
    {
      "id": "189f7e81-1391-4baa-baa1-63419f92cccb",
      "name": "Check Approval Decision",
      "type": "n8n-nodes-base.if",
      "position": [
        3900,
        640
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "451bfdfc-f645-4e3c-91cc-895558f45b11",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.data['Approve Invoice?'] }}",
              "rightValue": "Yes"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "24d89a38-91cc-429d-af6a-8616d67c1e03",
      "name": "Send Rejection Alert",
      "type": "n8n-nodes-base.gmail",
      "position": [
        4040,
        900
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=Hi Finance Team,\n\nAn invoice from {{ $('Invoice Parser AI Agent').item.json.output.vendor_name }} has been disapproved during the approval process.\n\nReviewed By: {{ $('Send Invoice for Approval').item.json.data['Reviewed By'] }}\nApproval Notes: {{ $('Send Invoice for Approval').item.json.data['Approval Notes'] }}\n\nPlease review and follow up as needed.\n\nThank you,\nAutomated Invoice System\n\n",
        "options": {
          "appendAttribution": false
        },
        "subject": "=[Alert] Invoice Disapproved \u2013 {{ $('Invoice Parser AI Agent').item.json.output.vendor_name }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "5a2f9411-4233-4173-8541-53ba13de6268",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4400,
        340
      ],
      "parameters": {
        "color": 4,
        "width": 380,
        "height": 760,
        "content": "# \ud83d\udc4b Hi, I\u2019m Billy\n![My Photo](https://i.ibb.co/Gvn63Bzc/Billy-Christi-AI-Automation.jpg)\nI help businesses build **n8n workflows** & **AI automation projects**.  \nNeed help with n8n or AI Automation projects? \nContact me and let\u2019s build your automation together.\n\n\ud83d\udce9 **Email:** billychartanto@gmail.com  \n\ud83e\udd1d **n8n Creator:** [n8n.io/creators/billy](https://n8n.io/creators/billy/)\n\ud83c\udf10 **My n8n Projects:** [billychristi.com/n8n](https://www.billychristi.com/n8n)  \n\n\n\n---\n\ud83d\udca1 Feel free to get in touch if you\u2019d like help on your next automation project or if you have any feedback or thoughts to share.\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Invoice Parser AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Download Invoice PDF": {
      "main": [
        [
          {
            "node": "Extract Text from Drive PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Rejection Alert": {
      "main": [
        [
          {
            "node": "Insert Invoice Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Invoice Folder Monitor": {
      "main": [
        [
          {
            "node": "Download Invoice PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Approval Decision": {
      "main": [
        [
          {
            "node": "Insert Invoice Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Rejection Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Invoice Parser AI Agent": {
      "main": [
        [
          {
            "node": "Send Invoice for Approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Invoice Parser AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Monitor Email Attachments": {
      "main": [
        [
          {
            "node": "Extract Text from Email PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Invoice for Approval": {
      "main": [
        [
          {
            "node": "Check Approval Decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Invoice (PDF) Form": {
      "main": [
        [
          {
            "node": "Extract Text from Form PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text from Form PDF": {
      "main": [
        [
          {
            "node": "Invoice Parser AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text from Drive PDF": {
      "main": [
        [
          {
            "node": "Invoice Parser AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text from Email PDF": {
      "main": [
        [
          {
            "node": "Invoice Parser AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}