メール請求書データをGoogle Sheetsへ抽出

中級

これはFinance, AI分野の自動化ワークフローで、10個のノードを含みます。主にCode, Filter, GoogleDrive, GmailTrigger, GoogleSheetsなどのノードを使用、AI技術を活用したスマート自動化を実現。 GPT-4o AI 自動化を使用してメールから請求書データを Google スプレッドシートに抽出する

前提条件
  • Google Drive API認証情報
  • Googleアカウント + Gmail API認証情報
  • Google Sheets API認証情報
  • OpenAI API Key

カテゴリー

ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
  "meta": {
    "instanceId": "5aaf4236c70e34e423fbdb2c7b754d19253a933bb1476d548f75848a01e473cf",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "70ca3a90-55c8-4e46-9278-6a8fd3d107cd",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -1820,
        220
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "labelIds": [
            "Label_1393502052621954450"
          ]
        },
        "options": {
          "downloadAttachments": true
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f7dcff0f-7e98-4042-a33e-2fc32d876908",
      "name": "空白スプレッドシートの作成",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -780,
        220
      ],
      "parameters": {
        "title": "=invoice_{{ $now }}",
        "options": {},
        "resource": "spreadsheet",
        "sheetsUi": {
          "sheetValues": [
            {
              "title": "=invoice_details"
            }
          ]
        }
      },
      "executeOnce": false,
      "typeVersion": 4.5
    },
    {
      "id": "9769ad04-a41c-4d55-806a-042b7d00e131",
      "name": "インボイスフォルダへのスプレッドシート移動",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -560,
        220
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.spreadsheetId }}"
        },
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive",
          "cachedResultName": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1JIdajTJvK6gj4bRjniBJvHEJbQ1pn3AM",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1JIdajTJvK6gj4bRjniBJvHEJbQ1pn3AM",
          "cachedResultName": "invoices"
        },
        "operation": "move"
      },
      "typeVersion": 3
    },
    {
      "id": "f9dbfe55-70b0-4abc-9745-9f4a65d5d1c2",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1180,
        480
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {
          "responseFormat": "json_object"
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "7dME1fmMlkFyzFjq",
          "name": "OpenAi account 2"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "00c59142-6079-4e9c-9374-ad487e48f072",
      "name": "添付ファイル確認",
      "type": "n8n-nodes-base.filter",
      "position": [
        -1600,
        220
      ],
      "parameters": {
        "options": {
          "ignoreCase": false
        },
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "efd974d9-aa20-461a-86ae-6e0a16d1527d",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $('Gmail Trigger').item.binary }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "8a29ac14-be2b-468a-97fa-540d28e80006",
      "name": "インボイスデータ抽出",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -1380,
        220
      ],
      "parameters": {
        "options": {},
        "operation": "pdf",
        "binaryPropertyName": "={{ $('Attachment Verification').item.binary.keys() }}"
      },
      "typeVersion": 1
    },
    {
      "id": "ae08cdc8-fcf9-4891-be86-b2dcf6f35278",
      "name": "最終データの準備",
      "type": "n8n-nodes-base.code",
      "position": [
        -340,
        220
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of $input$json.output.first().json.outputeach one\n\nlet invoice_details = $('Invoice AI Agent').item.json.output\n\nreturn JSON.parse(invoice_details)"
      },
      "typeVersion": 2
    },
    {
      "id": "7615a5b0-8761-43e2-82b0-32ac5c772f44",
      "name": "インボイスデータ付き最終スプレッドシート",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -140,
        220
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [
            {
              "id": "billed_to",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "billed_to",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "invoice_number",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "invoice_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "date_of_issue",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "date_of_issue",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "due_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "due_date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "item_0_description",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "item_0_description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "item_0_quantity",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "item_0_quantity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "item_0_rate",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "item_0_rate",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "item_0_amount",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "item_0_amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "tax_0_cgst_rate",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "tax_0_cgst_rate",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "tax_0_cgst_amount",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "tax_0_cgst_amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "tax_0_sgst_rate",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "tax_0_sgst_rate",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "tax_0_sgst_amount",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "tax_0_sgst_amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "item_0_total_amount",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "item_0_total_amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subtotal",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "subtotal",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "total",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "total",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "terms",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "terms",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "conditions_instructions",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "conditions_instructions",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "company_name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "company_name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "company_mobile",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "company_mobile",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "company_email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "company_email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "company_website",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "company_website",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "payment_transaction_ids",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "payment_transaction_ids",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "mode_of_payment",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "mode_of_payment",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "billing_address",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "billing_address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "shipping_address",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "shipping_address",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "place_of_supply",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "place_of_supply",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "place_of_delivery",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "place_of_delivery",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "gst_registration_no",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "gst_registration_no",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "pan_no",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "pan_no",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "invoice_details"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Create blank spreadsheet').item.json.spreadsheetId }}"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "e68aa386-7150-4070-a5d7-1dcb963b620d",
      "name": "Invoice AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1160,
        220
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "you are an financial advisor , who reads the array of data to identify certain elements of an Invoice, from the input data and provide a json response. use only following specified keys \nfor example:\n{\n\"billed_to\": \"John\",\n\"invoice_number\": \"569871234\",\n\"date_of_issue\": \"2025-05-21\",\n\"due_date\": \"2025-05-25\",\n\"item_0_description\": \"Computer CPU\",\n\"item_0_quantity\": 6,\n\"item_0_rate\": 15,\n\"item_0_amount\": 90,\n\"item_1_description\": \"Chair Wooden\",\n\"item_1_quantity\": 8,\n\"item_1_rate\": 10,\n\"item_1_amount\": 80,\n\"subtotal\": 170.00,\n\"discount\": 20.00,\n\"total\": 150.00,\n\"terms\": \"Sold items not be acceptable\",\n\"conditions_instructions\": \"xyaABC\",\n\"company_name\": \"Digital Electronics\",\n\"company_mobile\": \"987654321\",\n\"company_email\": \"ayz@gmail.com\",\n\"company_website\": \"www.abc.com\"\n}"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9,
      "alwaysOutputData": false
    },
    {
      "id": "335a80c5-ad86-4379-b1a6-9a2ef7285f3c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2860,
        100
      ],
      "parameters": {
        "width": 880,
        "height": 1520,
        "content": "AI Invoice Processor Agent: Email to Structured Data\nAutomatically extract, analyze, and organize invoice data from Gmail attachments into structured Google Sheets. Perfect for:\n✅ Accountants & bookkeepers — eliminate manual data entry from invoices\n✅ Small businesses — streamline invoice processing and tracking\n✅ Finance teams — automate accounts payable workflows\n\n⚙️ What's Used\nn8n Nodes:\nGmail Trigger → File Extraction → AI Agent → OpenAI Chat Model → Google Sheets → Google Drive\nExternal Tools:\n\nGmail API – Monitor specific labeled emails with attachments\nPDF Extraction – Convert invoice PDFs to readable text\nOpenAI GPT-4 – Intelligent invoice data extraction and structuring\nGoogle Sheets – Create organized spreadsheets with invoice details\nGoogle Drive – Automatically organize files in invoice folders\n\n\n🔑 Setup – Credentials Needed\n\nGmail OAuth2 → Access emails and download attachments\nOpenAI API Key → For AI-powered invoice data extraction\nGoogle Sheets OAuth2 → Create and populate spreadsheets\nGoogle Drive OAuth2 → Organize files in designated folders\n\n\n📧 Gmail Setup Required\nCreate a Gmail label (e.g., \"Invoice Processing\") and apply it to emails containing invoice attachments. The workflow will monitor this label for new emails every minute.\n\n🚀 Workflow Steps\n\nEmail Monitoring\nContinuously watches Gmail for new emails with specific labels and attachments\nAttachment Verification\nFilters emails to ensure they contain PDF attachments before processing\nData Extraction\nConverts PDF invoices to text and extracts readable content\nAI-Powered Analysis\nGPT processes invoice text and extracts structured data including:\n\nCompany details and contact information\nInvoice numbers, dates, and due dates\nLine items with quantities, rates, and amounts\nTax calculations (CGST, SGST, VAT)\nPayment terms and billing addresses\n\n\nSpreadsheet Creation\nCreates timestamped Google Sheets with organized invoice data\nFile Organization\nMoves processed spreadsheets to designated Drive folders for easy access\n\n\n📊 Extracted Data Fields\nThe AI identifies and organizes 25+ invoice elements:\n\nHeader Info: Billed to, invoice number, dates\nLine Items: Description, quantity, rate, amount\nTax Details: CGST/SGST rates and amounts\nCompany Info: Name, contact details, GST numbers\nPayment Info: Transaction IDs, payment methods\nAddresses: Billing, shipping, delivery locations\n\n\n💡 Pro Tips\n\nUse clear Gmail labels for different invoice types (vendors, clients, etc.)\nEnsure invoice PDFs are text-based (not scanned images) for best results\nCreate separate Drive folders for different accounting periods\nReview AI extraction accuracy and refine prompts as needed\nSet up email filters to automatically apply labels to vendor emails\n\n\n🛠️ Customize It\n\nAdd invoice approval workflows with email notifications\nConnect to accounting software (QuickBooks, Xero, SAP)\nInclude OCR processing for scanned invoice images\nAdd duplicate invoice detection and alerts\nCreate automated payment reminders based on due dates"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "70ca3a90-55c8-4e46-9278-6a8fd3d107cd": {
      "main": [
        [
          {
            "node": "00c59142-6079-4e9c-9374-ad487e48f072",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e68aa386-7150-4070-a5d7-1dcb963b620d": {
      "main": [
        [
          {
            "node": "f7dcff0f-7e98-4042-a33e-2fc32d876908",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f9dbfe55-70b0-4abc-9745-9f4a65d5d1c2": {
      "ai_languageModel": [
        [
          {
            "node": "e68aa386-7150-4070-a5d7-1dcb963b620d",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "8a29ac14-be2b-468a-97fa-540d28e80006": {
      "main": [
        [
          {
            "node": "e68aa386-7150-4070-a5d7-1dcb963b620d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ae08cdc8-fcf9-4891-be86-b2dcf6f35278": {
      "main": [
        [
          {
            "node": "7615a5b0-8761-43e2-82b0-32ac5c772f44",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "00c59142-6079-4e9c-9374-ad487e48f072": {
      "main": [
        [
          {
            "node": "8a29ac14-be2b-468a-97fa-540d28e80006",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f7dcff0f-7e98-4042-a33e-2fc32d876908": {
      "main": [
        [
          {
            "node": "9769ad04-a41c-4d55-806a-042b7d00e131",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "9769ad04-a41c-4d55-806a-042b7d00e131": {
      "main": [
        [
          {
            "node": "ae08cdc8-fcf9-4891-be86-b2dcf6f35278",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
よくある質問

このワークフローの使い方は?

上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。

このワークフローはどんな場面に適していますか?

中級 - 財務, 人工知能

有料ですか?

このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。

関連ワークフロー

ワークフロー情報
難易度
中級
ノード数10
カテゴリー2
ノードタイプ9
難易度説明

経験者向け、6-15ノードの中程度の複雑さのワークフロー

作成者
Yaron Been

Yaron Been

@yaron-nofluff

Building AI Agents and Automations | Growth Marketer | Entrepreneur | Book Author & Podcast Host

外部リンク
n8n.ioで表示

このワークフローを共有

カテゴリー

カテゴリー: 34