{
  "name": "Extract invoice data from Google Drive to Sheets with Mistral OCR and Gemini",
  "nodes": [
    {
      "id": "a8716edb-e05a-43a5-a38f-384fa05e93cf",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        320,
        -80
      ]
    },
    {
      "id": "bce283e2-29fd-47a1-9cfe-c4cf50f4e35d",
      "name": "On new file in Google Drive",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        320,
        260
      ]
    },
    {
      "id": "160e8e02-8f70-4c8f-a3c4-a94cf2325b82",
      "name": "Load files from Google Drive folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        880,
        260
      ]
    },
    {
      "id": "ad1c63fb-4aae-48a2-8329-20afd04e069d",
      "name": "Filter processed files",
      "type": "n8n-nodes-base.merge",
      "position": [
        1360,
        140
      ]
    },
    {
      "id": "1e689ab2-32d1-453f-b30b-61eb8ac5e1db",
      "name": "Download file for OCR",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1560,
        140
      ]
    },
    {
      "id": "37e21a39-2383-4934-9b41-81b76c484974",
      "name": "Get already processed rows from Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1160,
        -80
      ]
    },
    {
      "id": "140113e8-31da-45f2-901a-cb83bd183478",
      "name": "Save data to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3640,
        60
      ]
    },
    {
      "id": "fa83c3b3-b58d-40c8-b94e-93925347b2de",
      "name": "Mistral Upload",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2060,
        120
      ]
    },
    {
      "id": "f0aef4a8-ca9a-48a1-b94e-4879adf679c1",
      "name": "Mistral Signed URL",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2260,
        120
      ]
    },
    {
      "id": "165556d9-c325-4eb9-b1b2-4983f3fda5a4",
      "name": "Mistral DOC OCR",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2460,
        100
      ]
    },
    {
      "id": "849bbcd3-122d-4375-b6ae-920e6c5d2b9e",
      "name": "extract schema",
      "type": "n8n-nodes-base.code",
      "position": [
        920,
        -80
      ]
    },
    {
      "id": "ff80d6f4-6758-482c-b5eb-3fa927525948",
      "name": "Join OCR Pages and remove id field",
      "type": "n8n-nodes-base.code",
      "position": [
        2840,
        100
      ]
    },
    {
      "id": "24f5b810-03cc-49d7-bc64-7748f6be9686",
      "name": "Add google drive Id back",
      "type": "n8n-nodes-base.code",
      "position": [
        3380,
        60
      ]
    },
    {
      "id": "407bd6d8-8b90-47bd-84f8-c15f32ea1cf4",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        3060,
        280
      ]
    },
    {
      "id": "c7ceb651-3f48-49f9-a2f8-f933a63311a8",
      "name": "Mistral Upload1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2080,
        340
      ]
    },
    {
      "id": "27c0f663-3833-4f67-8f2d-5efcd1a9b8a2",
      "name": "Mistral Signed URL1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2260,
        340
      ]
    },
    {
      "id": "027a9c9c-4ebd-497a-8e61-a3ee63b99666",
      "name": "Mistral IMAGE OCR",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2460,
        320
      ]
    },
    {
      "id": "be5e7900-7ae8-4c56-83d5-d0984767abff",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1780,
        140
      ]
    },
    {
      "id": "f33ce8fa-1412-4889-b586-130119d4bc4b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        460
      ],
      "parameters": {
        "width": 220,
        "height": 80,
        "content": "### Modify Folder source"
      }
    },
    {
      "id": "fdc0a222-8962-4d4a-a50c-abd347794430",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3560,
        260
      ],
      "parameters": {
        "width": 320,
        "height": 100,
        "content": "### File Ids\nYou can view the files using Id from the first column. replace the <Id> below\nhttps://drive.google.com/file/d/<Id>/view"
      }
    },
    {
      "id": "f9e36727-f376-4bb3-b32f-bd55eab82e88",
      "name": "Field Extractor",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3020,
        60
      ]
    },
    {
      "id": "73cc08ed-caa1-405b-8b15-11f2a375fcd9",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        260,
        480
      ],
      "parameters": {
        "width": 220,
        "height": 80,
        "content": "### Set interval for checking drive folder and pull new files"
      }
    },
    {
      "id": "d7df816d-3aee-4bd8-9f12-76c23d2108dd",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        580,
        -380
      ],
      "parameters": {
        "width": 300,
        "height": 140,
        "content": "### Select Sheet\n  \nAdd column headers in the sheet to which you save data on row one to specify which fields you are interested in extracting. "
      }
    },
    {
      "id": "29782ff3-dbdf-4132-90d2-36a9fafa5815",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        -180
      ],
      "parameters": {
        "width": 200,
        "height": 80,
        "content": "### Select sheet"
      }
    },
    {
      "id": "3d60e92c-2966-4ed3-900a-582cca0f0b8c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3600,
        -40
      ],
      "parameters": {
        "width": 200,
        "height": 80,
        "content": "### Select sheet to save data (same as at the start)"
      }
    },
    {
      "id": "3cabcbee-b685-4d9a-9f11-9a3328d70fcd",
      "name": "Get Fields Schema",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        680,
        -80
      ]
    },
    {
      "id": "2beee512-688a-4c4a-a4eb-b4a20956ead2",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        580,
        -220
      ],
      "parameters": {
        "width": 300,
        "height": 120,
        "content": ">> ### First column header in cell A1 MUST BE \"Id\". Id tracks the google drive Id and ensures the workflow is not processing previously processed files"
      }
    },
    {
      "id": "314e28c9-07c3-45f5-acb2-c2307d935638",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1540,
        40
      ],
      "parameters": {
        "width": 160,
        "height": 80,
        "content": "Uses drive ID - no need to modify"
      }
    },
    {
      "id": "a3e0322c-3224-40fe-9e82-28274a69d77c",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2040,
        -20
      ],
      "parameters": {
        "width": 520,
        "height": 80,
        "content": "Requires Mistral API Key for La Platforme\nhttps://mistral.ai/products/la-plateforme"
      }
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Mistral Upload1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mistral Upload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mistral Upload": {
      "main": [
        [
          {
            "node": "Mistral Signed URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "extract schema": {
      "main": [
        [
          {
            "node": "Get already processed rows from Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Field Extractor": {
      "main": [
        [
          {
            "node": "Add google drive Id back",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mistral DOC OCR": {
      "main": [
        [
          {
            "node": "Join OCR Pages and remove id field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mistral Upload1": {
      "main": [
        [
          {
            "node": "Mistral Signed URL1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Fields Schema": {
      "main": [
        [
          {
            "node": "extract schema",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mistral IMAGE OCR": {
      "main": [
        [
          {
            "node": "Join OCR Pages and remove id field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mistral Signed URL": {
      "main": [
        [
          {
            "node": "Mistral DOC OCR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mistral Signed URL1": {
      "main": [
        [
          {
            "node": "Mistral IMAGE OCR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download file for OCR": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter processed files": {
      "main": [
        [
          {
            "node": "Download file for OCR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add google drive Id back": {
      "main": [
        [
          {
            "node": "Save data to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Field Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "On new file in Google Drive": {
      "main": [
        [
          {
            "node": "Load files from Google Drive folder",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Fields Schema",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Load files from Google Drive folder",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Fields Schema",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Join OCR Pages and remove id field": {
      "main": [
        [
          {
            "node": "Field Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load files from Google Drive folder": {
      "main": [
        [
          {
            "node": "Filter processed files",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get already processed rows from Sheets": {
      "main": [
        [
          {
            "node": "Filter processed files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}