{
  "name": "Gmail Invoice Parser to Google Sheets",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [{ "mode": "everyMinute" }]
        },
        "filters": {
          "readStatus": "unread",
          "subject": "invoice"
        },
        "options": {
          "downloadAttachments": true
        }
      },
      "id": "gips0001-0001-4000-8000-000000000001",
      "name": "Watch for Invoice Emails",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1,
      "position": [240, 300]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are an accounting assistant. Extract invoice details from the email body. Return JSON: {\"vendor\": \"...\", \"invoiceNumber\": \"...\", \"amount\": 0.00, \"currency\": \"USD\", \"dueDate\": \"YYYY-MM-DD\", \"description\": \"...\"}. If a field is not found use null."
            },
            {
              "role": "user",
              "content": "From: {{ $json.from }}\\nSubject: {{ $json.subject }}\\nDate: {{ $json.date }}\\n\\n{{ $json.text }}"
            }
          ]
        },
        "options": {
          "temperature": 0.0,
          "maxTokens": 400
        }
      },
      "id": "gips0001-0002-4000-8000-000000000002",
      "name": "Extract Invoice Fields",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [460, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "field1",
              "name": "invoice",
              "value": "={{ JSON.parse($json.message.content) }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "gips0001-0003-4000-8000-000000000003",
      "name": "Parse Invoice JSON",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [680, 300]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": { "__rl": true, "mode": "id", "value": "={{ $env.INVOICE_SHEET_ID }}" },
        "sheetName": { "__rl": true, "mode": "name", "value": "Invoices" },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Vendor": "={{ $json.invoice.vendor }}",
            "Invoice Number": "={{ $json.invoice.invoiceNumber }}",
            "Amount": "={{ $json.invoice.amount }}",
            "Currency": "={{ $json.invoice.currency }}",
            "Due Date": "={{ $json.invoice.dueDate }}",
            "Description": "={{ $json.invoice.description }}",
            "Received": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      },
      "id": "gips0001-0004-4000-8000-000000000004",
      "name": "Append to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [900, 300]
    }
  ],
  "connections": {
    "Watch for Invoice Emails": {
      "main": [[{ "node": "Extract Invoice Fields", "type": "main", "index": 0 }]]
    },
    "Extract Invoice Fields": {
      "main": [[{ "node": "Parse Invoice JSON", "type": "main", "index": 0 }]]
    },
    "Parse Invoice JSON": {
      "main": [[{ "node": "Append to Google Sheets", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {},
  "pinData": {}
}
