{
  "name": "Demo — Invoice Email to Sheet",
  "active": false,
  "nodes": [
    {
      "id": "c4818d55-b21e-4a51-8e56-a8ad8f58b0a2",
      "name": "README",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -80,
        -420
      ],
      "parameters": {
        "content": "## Invoice email to Google Sheets, with a summary\n\n**What it does:** every new email with a PDF invoice is read by AI, one row is added to your sheet, and you get a short summary email.\n\n**Setup (5 minutes):**\n1. Gmail Trigger: connect your Gmail account. Change the search in Filters if your invoices use another subject.\n2. Claude Model: add your Anthropic API key (or swap in any chat model).\n3. Add Row to Sheet: connect Google Sheets, paste your spreadsheet ID, and make a sheet named \"Invoices\" with the columns Vendor, Invoice Number, Invoice Date, Total, Currency, Received At.\n4. Send Summary Email: put your own email address in \"To\".\n5. Run it once with a test email, then Publish.\n\nBuilt as a demo by Mina Saad (mina-saad.com). Sample setup, no credentials included.",
        "height": 420,
        "width": 560,
        "color": 6
      }
    },
    {
      "id": "fbe3d442-8394-40f6-a410-96f343d02e17",
      "name": "Invoice Email",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.4,
      "position": [
        0,
        0
      ],
      "parameters": {
        "authentication": "oAuth2",
        "event": "messageReceived",
        "simple": false,
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "filters": {
          "q": "has:attachment filename:pdf subject:invoice",
          "readStatus": "unread"
        },
        "options": {
          "downloadAttachments": true,
          "dataPropertyAttachmentsPrefixName": "attachment_"
        }
      }
    },
    {
      "id": "a847944e-fb4f-4585-aa45-115115e0ef90",
      "name": "Read Invoice PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        240,
        0
      ],
      "parameters": {
        "operation": "pdf",
        "binaryPropertyName": "attachment_0",
        "options": {
          "joinPages": true,
          "maxPages": 5
        }
      }
    },
    {
      "id": "119f3798-9cac-48d4-9fa4-d613f4b7a9a5",
      "name": "Extract Invoice Fields",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        480,
        0
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "schemaType": "fromAttributes",
        "attributes": {
          "attributes": [
            {
              "name": "vendor",
              "type": "string",
              "description": "Company that sent the invoice",
              "required": true
            },
            {
              "name": "invoice_number",
              "type": "string",
              "description": "Invoice number or reference",
              "required": true
            },
            {
              "name": "invoice_date",
              "type": "date",
              "description": "Invoice date",
              "required": false
            },
            {
              "name": "total",
              "type": "number",
              "description": "Total amount due, a number only",
              "required": true
            },
            {
              "name": "currency",
              "type": "string",
              "description": "Three-letter currency code, for example EGP or USD",
              "required": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "ac1fb109-81bc-47b9-9c44-f31a150da892",
      "name": "Claude Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "typeVersion": 1.5,
      "position": [
        480,
        220
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "claude-haiku-4-5",
          "cachedResultName": "Claude Haiku 4.5"
        },
        "options": {}
      }
    },
    {
      "id": "f82e7d9b-de3d-48e0-a799-1753cc24cc12",
      "name": "Add Row to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        760,
        0
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Invoices",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "schema": [
            {
              "id": "Vendor",
              "displayName": "Vendor",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Invoice Number",
              "displayName": "Invoice Number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Invoice Date",
              "displayName": "Invoice Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Total",
              "displayName": "Total",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Currency",
              "displayName": "Currency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Received At",
              "displayName": "Received At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "matchingColumns": [],
          "value": {
            "Vendor": "={{ $json.output.vendor }}",
            "Invoice Number": "={{ $json.output.invoice_number }}",
            "Invoice Date": "={{ $json.output.invoice_date }}",
            "Total": "={{ $json.output.total }}",
            "Currency": "={{ $json.output.currency }}",
            "Received At": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      }
    },
    {
      "id": "af328392-0eaa-4fee-b9c3-9b2e2a78b049",
      "webhookId": "facd8231-2c83-4b1c-9347-22811efca17c",
      "name": "Send Summary Email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1000,
        0
      ],
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "YOUR_EMAIL",
        "subject": "=New invoice: {{ $('Extract Invoice Fields').item.json.output.vendor }}",
        "emailType": "text",
        "message": "=New invoice saved to your sheet.\n\nVendor: {{ $('Extract Invoice Fields').item.json.output.vendor }}\nInvoice: {{ $('Extract Invoice Fields').item.json.output.invoice_number }}\nTotal: {{ $('Extract Invoice Fields').item.json.output.total }} {{ $('Extract Invoice Fields').item.json.output.currency }}",
        "options": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "Invoice Email": {
      "main": [
        [
          {
            "node": "Read Invoice PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Invoice PDF": {
      "main": [
        [
          {
            "node": "Extract Invoice Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Invoice Fields": {
      "main": [
        [
          {
            "node": "Add Row to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Row to Sheet": {
      "main": [
        [
          {
            "node": "Send Summary Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Claude Model": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Invoice Fields",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}