{
  "name": "Document Data Extraction",
  "nodes": [
    {
      "parameters": {
        "folderId": "YOUR_FOLDER_ID"
      },
      "name": "New Invoice File",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "notes": "Triggers when a new file is added to a specific Google Drive folder. **ACTION REQUIRED:** Configure Google Drive credentials and specify the Folder ID.",
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "placeholder",
          "name": "Google Drive Account"
        }
      }
    },
    {
      "parameters": {
        "url": "https://api.ocr.space/parse/image",
        "options": {},
        "bodyParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "YOUR_OCR_SPACE_API_KEY"
            },
            {
              "name": "url",
              "value": "={{ $json.webContentLink }}"
            }
          ]
        }
      },
      "name": "Scan with OCR",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        650,
        300
      ],
      "notes": "Sends the file to the ocr.space API to extract text. **ACTION REQUIRED:** Get a free API key from ocr.space and paste it here."
    },
    {
      "parameters": {
        "url": "https://api.example.com/v1/chat/completions",
        "options": {},
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "gpt-4"
            },
            {
              "name": "messages",
              "value": "={{ [ { \"role\": \"system\", \"content\": \"You are an expert invoice parser. Extract the following fields from the OCR text and respond with only a valid JSON object: invoiceNumber, vendor, totalAmount, dueDate.\" }, { \"role\": \"user\", \"content\": \"Here is the OCR text: \" + $json[\"ParsedResults\"][0][\"ParsedText\"] + \"\" } ] }}"
            }
          ]
        },
        "authentication": "headerAuth"
      },
      "name": "Extract Invoice Data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        850,
        300
      ],
      "notes": "Sends the OCR text to an LLM to extract structured data. **ACTION REQUIRED:** Configure LLM URL and authentication.",
      "credentials": {
        "httpHeaderAuth": {
          "id": "placeholder",
          "name": "LLM API Key"
        }
      }
    },
    {
      "parameters": {},
      "name": "Save to Database",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ],
      "notes": "This is a placeholder for saving the data to a database. **ACTION REQUIRED:** Replace with your database node (Postgres, MySQL, etc.), configure credentials, and map the data fields."
    }
  ],
  "connections": {
    "New Invoice File": {
      "main": [
        [
          {
            "node": "Scan with OCR",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scan with OCR": {
      "main": [
        [
          {
            "node": "Extract Invoice Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Invoice Data": {
      "main": [
        [
          {
            "node": "Save to Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}