{
  "name": "Extract Amazon invoice data with Airtop, OpenAI, and Google Sheets",
  "nodes": [
    {
      "id": "d5ee6a1f-b49a-4450-b511-3aa850625559",
      "name": "Sticky Note - Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        320,
        -400
      ],
      "parameters": {
        "width": 716,
        "height": 1320,
        "content": "# Read Amazon invoices with AI and log them to Google Sheets\n\nTakes a sheet of Amazon invoice links, opens each one in a cloud browser, screenshots it, files the image in a dated Google Drive folder, and uses AI to read the company, invoice number, date, taxes and total into a spreadsheet row. Built as the follow-up to a workflow that collects the invoice links.\n\n### How it works\n1. A nightly schedule reads the invoice links from your sheet and keeps only rows dated today.\n2. Each invoice is handled one at a time. Airtop opens a cloud browser on the invoice page, zooms out so the whole invoice fits, and takes a screenshot.\n3. The screenshot is uploaded into the current month's folder in Google Drive, then downloaded back so both the file and its shareable links travel together.\n4. One AI agent reads the image, a second turns that reading into strict JSON, and an auto-fixing parser retries if the format is wrong.\n5. The extracted fields are appended to a monthly tab in your spreadsheet and the browser session is closed.\n\n### Setup\n1. Add your Airtop, OpenAI, Google Sheets and Google Drive credentials to the placeholder nodes.\n2. Point the two Google Sheets nodes at your own spreadsheet. The source tab needs an Invoice URL and Date column.\n3. In Google Drive, create folders named by month, for example 2026-04, and select your drive on the Find this month folder node.\n4. In Airtop, create a browser profile, log into Amazon inside it once, and put the profile name in the Start browser session node.\n\n### Customization\nEdit the field list in the two AI agent prompts and the output parser to capture different invoice fields."
      },
      "typeVersion": 1
    },
    {
      "id": "d53e8f68-b4b8-4aa0-9fc0-9a2021d10153",
      "name": "Sticky Note - Section 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 1140,
        "height": 340,
        "content": "## 1. Get the invoice links\nToday's rows are read from your sheet and handled one invoice at a time, so a failure on one link does not stop the rest."
      },
      "typeVersion": 1
    },
    {
      "id": "97491f7f-d45a-4958-a2b8-7c4428403744",
      "name": "Sticky Note - Section 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2336,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 1698,
        "height": 340,
        "content": "## 2. Screenshot each invoice\nA cloud browser opens the invoice, zooms out so the whole page fits in one shot, then captures it as an image."
      },
      "typeVersion": 1
    },
    {
      "id": "c33b7d26-6c17-4837-a635-a112b138aa03",
      "name": "Sticky Note - Section 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4080,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 1988,
        "height": 580,
        "content": "## 3. File it in Drive\nThe image goes into the folder named after the current month, then comes back with a view link and a folder link attached."
      },
      "typeVersion": 1
    },
    {
      "id": "7aa17e38-c1bf-4d81-8089-8c152360a86e",
      "name": "Sticky Note - Section 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        6128,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 1148,
        "height": 820,
        "content": "## 4. Read it with AI and log it\nOne agent reads the image, another returns strict JSON, and the fields are appended to a monthly tab. The browser session is then closed."
      },
      "typeVersion": 1
    },
    {
      "id": "cd927639-5d67-48ca-b82d-df83476fb114",
      "name": "Start browser session",
      "type": "n8n-nodes-base.airtop",
      "position": [
        2400,
        160
      ],
      "parameters": {
        "profileName": "YOUR_AIRTOP_PROFILE_NAME",
        "timeoutMinutes": 5,
        "additionalFields": {},
        "saveProfileOnTermination": true
      },
      "typeVersion": 1
    },
    {
      "id": "fa8f26ab-1e50-45a1-803c-2fc8f572f3c5",
      "name": "Open the invoice page",
      "type": "n8n-nodes-base.airtop",
      "position": [
        2688,
        160
      ],
      "parameters": {
        "url": "={{ $('Loop over invoices').item.json['Invoice URL '] }}",
        "resource": "window",
        "getLiveView": true,
        "additionalFields": {}
      },
      "typeVersion": 1
    },
    {
      "id": "e147578c-cff2-41e5-976b-c1d1bf852482",
      "name": "Loop over invoices",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        2064,
        160
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "7ee60682-946d-4efc-8369-cbb3867c9710",
      "name": "Wait for page to load",
      "type": "n8n-nodes-base.wait",
      "position": [
        2960,
        160
      ],
      "parameters": {
        "amount": 10
      },
      "typeVersion": 1.1
    },
    {
      "id": "460ae9d4-08f4-4d13-a800-e2ea6b243f64",
      "name": "Screenshot the invoice",
      "type": "n8n-nodes-base.airtop",
      "position": [
        3808,
        160
      ],
      "parameters": {
        "resource": "window",
        "operation": "takeScreenshot",
        "outputImageAsBinary": true
      },
      "typeVersion": 1
    },
    {
      "id": "3adc075f-a51f-456a-8909-1742ad3d5b71",
      "name": "Wait for zoom to apply",
      "type": "n8n-nodes-base.wait",
      "position": [
        3520,
        160
      ],
      "parameters": {
        "amount": 10
      },
      "typeVersion": 1.1
    },
    {
      "id": "2e457f39-8a5f-4517-8a83-707732bc438c",
      "name": "Is it a PDF or an image?",
      "type": "n8n-nodes-base.if",
      "position": [
        4160,
        160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "7fd9bfaa-74f0-4276-8de8-e8d5d74fd8ea",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $input.item.binary.data.mimeType }}",
              "rightValue": "application/pdf"
            },
            {
              "id": "image-condition-1",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $input.item.binary.data.mimeType }}",
              "rightValue": "image/jpeg"
            },
            {
              "id": "image-condition-2",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $input.item.binary.data.mimeType }}",
              "rightValue": "image/png"
            },
            {
              "id": "image-condition-3",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $input.item.binary.data.mimeType }}",
              "rightValue": "image/jpg"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "57cfa068-a86d-407d-a761-0f10d98177be",
      "name": "Add invoice data to sheet",
      "type": "n8n-nodes-base.googleSheets",
      "maxTries": 5,
      "position": [
        6752,
        160
      ],
      "parameters": {
        "columns": {
          "value": {
            "Term": "={{ $json.output.term }}",
            "PDF URL": "=https://drive.google.com/file/d/{{ $('Download invoice back').item.json.id }}/view",
            "VAT Tax": "={{ $json.output.VAT_Tax ||\" \" }}",
            "Sales Tax": "={{ $json.output.sales_tax }}",
            "Drive Link": "=https://drive.google.com/drive/folders/{{ $('Download invoice back').item.json.parents[0] }}",
            "Paid Status": "={{ $json.output.paid_status }}",
            "Company Name": "={{ $json.output.company_name }}",
            "Invoice Date": "={{ $json.output.invoice_date }}",
            "Total Amount": "={{ $json.output.total_amount }}",
            "PDF  FileName": "={{ $json.output.pdf_filename }}",
            "Invoice Number": "={{ $json.output.invoice_number }}",
            "Invoice Captured Date": "={{ $now.toFormat(\"dd LLL yyyy\") }}"
          },
          "schema": [
            {
              "id": "Company Name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Company Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "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": "VAT Tax",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "VAT Tax",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sales Tax",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Sales Tax",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Total Amount",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Total Amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Paid Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Paid Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Term",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Term",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "PDF  FileName",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "PDF  FileName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "PDF URL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "PDF URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Drive Link",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Drive Link",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Invoice Captured Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Invoice Captured Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $now.format(\"MMMM yyyy\") }}"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID",
          "cachedResultName": "Your invoice spreadsheet"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.6,
      "waitBetweenTries": 5000
    },
    {
      "id": "8f534b1a-d3ae-49c0-84d1-f0588aeaed2b",
      "name": "Combine file and folder",
      "type": "n8n-nodes-base.merge",
      "position": [
        5008,
        160
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combinationMode": "mergeByPosition"
      },
      "typeVersion": 2.1,
      "alwaysOutputData": true
    },
    {
      "id": "33c88500-945e-41c9-b93f-0421a9a6f5bf",
      "name": "Find this month folder in Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        4448,
        160
      ],
      "parameters": {
        "filter": {
          "driveId": {
            "__rl": true,
            "mode": "list",
            "value": "YOUR_SHARED_DRIVE_ID",
            "cachedResultName": "Your Drive"
          }
        },
        "options": {},
        "resource": "fileFolder",
        "queryString": "={{ $now.format('yyyy-MM') }}"
      },
      "typeVersion": 3
    },
    {
      "id": "761ec177-f0f9-40fc-ba99-a0c7eaf814dd",
      "name": "Download invoice back",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        5568,
        160
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "30118466-1525-42fa-902f-1e05c02b279f",
      "name": "Combine file and links",
      "type": "n8n-nodes-base.merge",
      "position": [
        5840,
        160
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combinationMode": "mergeByPosition"
      },
      "typeVersion": 2.1,
      "alwaysOutputData": true
    },
    {
      "id": "2ab14865-37ae-43a9-a558-8beaca107d70",
      "name": "Read the invoice image",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        6192,
        160
      ],
      "parameters": {
        "text": "=You are a precise invoice/receipt extraction agent. Analyze the provided image thoroughly and return STRICT JSON only (no extra text, no markdown, no code blocks). \n\nCRITICAL INSTRUCTION: Read the ENTIRE image content carefully. Extract ALL visible text and numbers. Do NOT skip any part of the image analysis.\n\nINPUT VARIABLES (from n8n):\n- pdf_filename = {{ $('Combine file and links').item.json.fileName }}\n- pdfUrl = {{ $('Combine file and links').item.json.pdfUrl }}\n- driveLink = {{ $('Combine file and links').item.json.driveLink }}\n\nMANDATORY OUTPUT FORMAT (return exactly these keys with exact spelling):\n{\n  \"company_name\": \"...\",\n  \"invoice_number\": \"...\",\n  \"invoice_date\": \"Month DD, YYYY or N/A\",\n  \"VAT_Tax\": \"amount with original currency symbol or N/A\",\n  \"sales_tax\": \"amount with original currency symbol or N/A\",\n  \"total_amount\": \"final payable amount with currency symbol or N/A\",\n  \"paid_status\": \"Paid or Unpaid or Pending or N/A\",\n  \"term\": \"payment terms or N/A\",\n  \"pdf_filename\": \"{{ $('Combine file and links').item.json.fileName }}\",\n  \"pdfUrl\": \"{{ $('Combine file and links').item.json.pdfUrl }}\",\n  \"driveLink\": \"{{ $('Combine file and links').item.json.driveLink }}\"\n}\n\nDETAILED EXTRACTION RULES:\n\n1) Company Name - MANDATORY EXTRACTION:\n   - Look at TOP of document, logo area, header section\n   - Find company issuing the invoice (Amazon, Flipkart, etc.)\n   - Check \"From:\", \"Seller:\", \"Billed by:\" sections\n   - Use the PRIMARY business name, ignore subsidiary names\n\n2) Invoice Number - SYSTEMATIC SEARCH:\n   - First priority: \"Invoice #\", \"Invoice No:\", \"Invoice Number:\"\n   - Second priority: \"Bill No:\", \"Bill Number:\", \"Receipt No:\"\n   - Third priority: \"Order #\", \"Order Number:\", \"Reference:\"\n   - Extract the COMPLETE number including prefixes/suffixes\n\n3) Invoice Date - COMPREHENSIVE DATE DETECTION:\n   - Look for \"Invoice Date:\", \"Date:\", \"Bill Date:\", \"Order Date:\"\n   - Accept ANY date format: DD/MM/YYYY, MM-DD-YYYY, DD-MMM-YYYY\n   - Convert to \"Month DD, YYYY\" (e.g., \"August 15, 2020\")\n   - If multiple dates, prefer \"Invoice Date\" over \"Order Date\"\n\n4) Tax Extraction - DETAILED ANALYSIS:\n   - VAT_Tax: Search for \"VAT\", \"GST\", \"IGST\", \"CGST\", \"SGST\", \"Value Added Tax\"\n   - sales_tax: Search for \"Sales Tax\", \"Tax\", \"Service Tax\" (US/general tax)\n   - Include currency symbol: $, \u20b9, \u20ac, \u00a3, etc.\n   - If only one tax type exists, put in appropriate field, set other to \"N/A\"\n\n5) Total Amount - PRIORITY HIERARCHY:\n   - Priority 1: \"Amount Due\", \"Balance Due\", \"Total Due\"\n   - Priority 2: \"Grand Total\", \"Final Total\", \"Net Total\"\n   - Priority 3: \"Total Amount\", \"Total\", \"Payable Amount\"\n   - Use HIGHEST priority available, include full currency formatting\n\n6) Paid Status - COMPREHENSIVE DETECTION:\n   - \"Paid\": Look for \"PAID\", \"PAID IN FULL\", \"Payment Received\", \"Completed\"\n   - \"Paid\": Also if \"Amount Due: $0.00\" or \"Balance: 0\"\n   - \"Unpaid\": Positive amount in \"Amount Due\" or explicit \"UNPAID\"\n   - \"Pending\": \"Pending Payment\", \"Processing\", \"Awaiting Payment\"\n   - Default: \"N/A\" if no clear indicators\n\n7) Payment Terms:\n   - Search for: \"Terms:\", \"Payment Terms:\", \"Net 30\", \"Net 15\", \"Due in\"\n   - Look for: \"Due on receipt\", \"Payment due by\", \"Due within X days\"\n   - Extract exactly as written in document\n\n8) Variable Assignment:\n   - ALWAYS include the three n8n variables exactly as provided\n   - Never modify or omit these variables\n\nPROCESSING INSTRUCTIONS:\n\nSTEP 1: Scan the ENTIRE image systematically from top to bottom\nSTEP 2: Identify if this is an invoice/receipt (must have financial elements)\nSTEP 3: Extract each field using the priority rules above  \nSTEP 4: Verify all currency symbols and amounts are preserved exactly\nSTEP 5: Format the JSON response with proper string values\n\nCRITICAL SUCCESS FACTORS:\n- Read EVERY piece of text in the image\n- Never assume or skip content\n- Preserve exact formatting of numbers and currency\n- Use consistent field extraction methodology\n- Return valid JSON with NO additional text\n\nFAILURE CONDITIONS:\n- If clearly NOT an invoice/receipt (no financial data), return blank response\n- If image is completely unreadable, extract whatever is visible\n\nOUTPUT REQUIREMENT: Return ONLY the JSON object, nothing else.",
        "options": {
          "systemMessage": "You are an expert at analyzing images of invoices, receipts, and bills. You can read text from images and extract structured data accurately."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2
    },
    {
      "id": "22e90ea1-4841-420b-9a2f-e732534b0cae",
      "name": "Close browser session",
      "type": "n8n-nodes-base.airtop",
      "position": [
        7040,
        160
      ],
      "parameters": {
        "operation": "terminate",
        "sessionId": "={{ $('Zoom out to fit the page').item.json.sessionId }}"
      },
      "typeVersion": 1
    },
    {
      "id": "8541daa8-0049-4c7e-80be-0df52cceaa85",
      "name": "Output Parser - Invoice fields",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        6576,
        640
      ],
      "parameters": {
        "jsonSchemaExample": "{\n\t\"company_name\": \"companyname\",\n\t\"invoice_number\": \"invoice_number\",\n  \"invoice_date\":\"invoicedate\",\n  \"sales_tax\":\"salestax\",\n  \"total_amount\":\"totalamount\",\n  \"paid_status\":\"paidstatus\",\n  \"term\":\"term\",\n  \"pdf_filename\":\"pdffilename\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "5b218dc0-5c0a-476a-974c-771ff2654dcc",
      "name": "Auto-fixing Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserAutofixing",
      "position": [
        6576,
        400
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "88d27dff-c425-41b7-9cee-ae22ad578f8d",
      "name": "Structure the invoice data",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        6480,
        160
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2
    },
    {
      "id": "bf7daed8-e870-4445-b871-dea508fc7659",
      "name": "Chat model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        6352,
        400
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "9e6bf897-20d7-41dd-a2f7-b32e9c8e669c",
      "name": "Upload invoice to Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        5280,
        160
      ],
      "parameters": {
        "name": "={{ $binary.data.fileName || 'invoice-' + $now.format('yyyyMMdd-HHmmss') }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "cd95c406-0bc6-4387-bf5b-c79c8fd76934",
      "name": "Build Drive links",
      "type": "n8n-nodes-base.code",
      "position": [
        5568,
        400
      ],
      "parameters": {
        "jsCode": "const results = [];\n\nfor (const file of $input.all()) {\n  const fileId = file.json.id;\n  const parentId = file.json.parents?.[0]; // parent folder ID\n  const fileName = file.json.name || file.json.fileName;\n  const fileType = file.json.fileType || (file.json.mimeType === 'application/pdf' ? 'PDF' : 'IMAGE');\n\n  results.push({\n    json: {\n      ...file.json, // keep existing fields\n      pdf_filename: fileName,\n      fileName: fileName,\n      fileType: fileType,\n      pdfUrl: `https://drive.google.com/file/d/${fileId}/view?usp=drivesdk`,\n      driveLink: `https://drive.google.com/drive/folders/${parentId}`\n    },\n    binary: file.binary // pass binary if needed downstream\n  });\n}\n\nreturn results;\n"
      },
      "typeVersion": 2
    },
    {
      "id": "87b88d80-1c5a-48ee-8dcb-ecd1489d8a11",
      "name": "Run every night",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1232,
        160
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 3
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3a88bdca-294a-4418-82c7-251b43732c0e",
      "name": "Zoom out to fit the page",
      "type": "n8n-nodes-base.airtop",
      "position": [
        3248,
        160
      ],
      "parameters": {
        "text": "70%",
        "resource": "interaction",
        "operation": "type",
        "pressEnterKey": true,
        "additionalFields": {},
        "elementDescription": "Please click on the '100%' dropdown in the center of the toolbar and select '70%' to zoom out the PDF"
      },
      "typeVersion": 1
    },
    {
      "id": "cbabf4c6-03bc-48bf-8b3b-74401e7be537",
      "name": "Pick the month folder",
      "type": "n8n-nodes-base.code",
      "position": [
        4720,
        160
      ],
      "parameters": {
        "jsCode": "// Drive search can return several matches - keep the folder named like 2026-04\nconst data = $input.all().map(item => item.json);\n\nconst match = data.find(item => /^\\d{4}-\\d{2}$/.test(item.name));\n\nreturn { id: match?.id };\n"
      },
      "typeVersion": 2
    },
    {
      "id": "fa4fa9f4-2495-44f9-acb5-489c8b674f78",
      "name": "Keep only today's rows",
      "type": "n8n-nodes-base.filter",
      "position": [
        1792,
        160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "6b574839-f8f0-4645-90d2-24dd63490a78",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.Date.trim() }}",
              "rightValue": "={{ new Date().toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric' }) }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "117725ce-c850-45ba-88eb-6a102c655d9e",
      "name": "Get invoice links from sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1504,
        160
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 789301638,
          "cachedResultName": "Amazon Invoices"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID",
          "cachedResultName": "Your invoice spreadsheet"
        }
      },
      "typeVersion": 4.7
    }
  ],
  "connections": {
    "Chat model": {
      "ai_languageModel": [
        [
          {
            "node": "Auto-fixing Output Parser",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Read the invoice image",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Structure the invoice data",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Run every night": {
      "main": [
        [
          {
            "node": "Get invoice links from sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Drive links": {
      "main": [
        [
          {
            "node": "Combine file and links",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Loop over invoices": {
      "main": [
        [],
        [
          {
            "node": "Start browser session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Close browser session": {
      "main": [
        [
          {
            "node": "Loop over invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download invoice back": {
      "main": [
        [
          {
            "node": "Combine file and links",
            "type": "main",
            "index": 0
          },
          {
            "node": "Build Drive links",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Open the invoice page": {
      "main": [
        [
          {
            "node": "Wait for page to load",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick the month folder": {
      "main": [
        [
          {
            "node": "Combine file and folder",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Start browser session": {
      "main": [
        [
          {
            "node": "Open the invoice page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for page to load": {
      "main": [
        [
          {
            "node": "Zoom out to fit the page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine file and links": {
      "main": [
        [
          {
            "node": "Read the invoice image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Keep only today's rows": {
      "main": [
        [
          {
            "node": "Loop over invoices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the invoice image": {
      "main": [
        [
          {
            "node": "Structure the invoice data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Screenshot the invoice": {
      "main": [
        [
          {
            "node": "Is it a PDF or an image?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for zoom to apply": {
      "main": [
        [
          {
            "node": "Screenshot the invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine file and folder": {
      "main": [
        [
          {
            "node": "Upload invoice to Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload invoice to Drive": {
      "main": [
        [
          {
            "node": "Download invoice back",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is it a PDF or an image?": {
      "main": [
        [
          {
            "node": "Combine file and folder",
            "type": "main",
            "index": 0
          },
          {
            "node": "Find this month folder in Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Zoom out to fit the page": {
      "main": [
        [
          {
            "node": "Wait for zoom to apply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add invoice data to sheet": {
      "main": [
        [
          {
            "node": "Close browser session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Auto-fixing Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Structure the invoice data",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structure the invoice data": {
      "main": [
        [
          {
            "node": "Add invoice data to sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get invoice links from sheet": {
      "main": [
        [
          {
            "node": "Keep only today's rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Output Parser - Invoice fields": {
      "ai_outputParser": [
        [
          {
            "node": "Auto-fixing Output Parser",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Find this month folder in Drive": {
      "main": [
        [
          {
            "node": "Pick the month folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "instanceId": null
  },
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  }
}