{
  "name": "Process scanned invoices with Google Drive, OCR & OpenAI to Google Sheets",
  "nodes": [
    {
      "id": "85702921-bc6d-4f5c-a1d5-429fb0b969ac",
      "name": "When clicking 'Execute workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -288,
        208
      ]
    },
    {
      "id": "0455ad8a-32bd-4c3f-a944-02a4c9a60f74",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1808,
        720
      ]
    },
    {
      "id": "ec4fa0f9-5f94-4490-8404-0666e655f4bd",
      "name": "Convert to File",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        1312,
        224
      ]
    },
    {
      "id": "09323ac4-58c7-4260-a11b-9d06f133b29f",
      "name": "Switch Mime Type",
      "type": "n8n-nodes-base.switch",
      "position": [
        880,
        400
      ]
    },
    {
      "id": "f15cfb3e-630b-47da-8318-dc58289f9e07",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        304,
        384
      ]
    },
    {
      "id": "33e127d5-6a47-4637-bcb2-d135a9dae63b",
      "name": "Set file identity",
      "type": "n8n-nodes-base.set",
      "position": [
        528,
        400
      ]
    },
    {
      "id": "89803795-7f66-495a-98fc-5024627a0242",
      "name": "Save base64",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        704,
        400
      ]
    },
    {
      "id": "2a32007a-337c-455c-9c96-52307e1efcc9",
      "name": "Re-set base64",
      "type": "n8n-nodes-base.set",
      "position": [
        1152,
        224
      ]
    },
    {
      "id": "7424c2eb-c3c3-46ff-82e4-2404f5cfc7fe",
      "name": "Check for new invoices",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -288,
        384
      ]
    },
    {
      "id": "a6839ddd-aacc-405b-a145-dd2152f91f6e",
      "name": "Download file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        128,
        384
      ]
    },
    {
      "id": "17d99786-f1e9-46e8-85a5-64d5d4ed65ad",
      "name": "Fetch 50 docs",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -64,
        208
      ]
    },
    {
      "id": "3ad34319-3715-4ff0-bf90-bfdd0f3a27e8",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        1152,
        480
      ]
    },
    {
      "id": "a7daca53-ed48-4af9-8c27-c18e4b5710e2",
      "name": "Identify CamScanner",
      "type": "n8n-nodes-base.if",
      "position": [
        1312,
        480
      ]
    },
    {
      "id": "a4df0641-b633-4ba4-bb43-31cacac9824b",
      "name": "Analyze Image",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1504,
        304
      ]
    },
    {
      "id": "4ac1d408-c1e7-4b8c-9be8-53612b0addfe",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        1664,
        304
      ]
    },
    {
      "id": "332f6947-3460-4dc6-984a-982a3829b121",
      "name": "Information Extractor",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "position": [
        1856,
        496
      ]
    },
    {
      "id": "57343929-604b-4b2f-bbc4-3c601033538d",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2176,
        496
      ]
    },
    {
      "id": "96efa1fd-74e9-4242-8256-26185c021340",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1104,
        688
      ],
      "parameters": {
        "width": 380,
        "height": 220,
        "content": "### Reroute to OCR if needed\n\n- Try to extract text directly from PDF. \n- CamScanner is not saving text in a readable format, so we fall back to the image path instead.\n- Otherwise we send the text di"
      }
    },
    {
      "id": "670c7063-2d84-4b34-b99b-68414f55e27f",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        512,
        304
      ],
      "parameters": {
        "width": 460,
        "height": 80,
        "content": "### Setting some handy values for later down the road\n"
      }
    },
    {
      "id": "21b66216-fd94-49cf-8050-0b165308c440",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        144
      ],
      "parameters": {
        "width": 696,
        "height": 308,
        "content": "### OCR for images and badly extracted PDFs \n"
      }
    },
    {
      "id": "ea1bc5c4-d8ed-47c0-a5b9-9bf6277342ca",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -352,
        16
      ],
      "parameters": {
        "width": 440,
        "height": 640,
        "content": "# Start here\n\n- Use the manual trigger to initialize the Google Drive folder with existing invoices\n- The scheduled trigger will identify new invoices and will start automatically"
      }
    },
    {
      "id": "ed831e1b-15fa-42c4-9deb-7a347745ab92",
      "name": "Mailgun",
      "type": "n8n-nodes-base.mailgun",
      "position": [
        688,
        144
      ]
    },
    {
      "id": "0f1ad01f-96c7-4c49-a346-040088f40b6c",
      "name": "Prepare a table",
      "type": "n8n-nodes-base.html",
      "position": [
        528,
        144
      ]
    },
    {
      "id": "8ba5e5ab-b8e8-4ec5-96fd-c9b541832b66",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        16
      ],
      "parameters": {
        "width": 340,
        "height": 112,
        "content": "# End here\n"
      }
    }
  ],
  "connections": {
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save base64": {
      "main": [
        [
          {
            "node": "Switch Mime Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Image": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download file": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch 50 docs": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Re-set base64": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "Analyze Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Prepare a table",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set file identity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare a table": {
      "main": [
        [
          {
            "node": "Mailgun",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch Mime Type": {
      "main": [
        [
          {
            "node": "Analyze Image",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Identify CamScanner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set file identity": {
      "main": [
        [
          {
            "node": "Save base64",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Identify CamScanner": {
      "main": [
        [
          {
            "node": "Re-set base64",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for new invoices": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking 'Execute workflow'": {
      "main": [
        [
          {
            "node": "Fetch 50 docs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}