Learning Timeline
Key Insights
Why Use Gemini API Instead of Standard Nodes?
The standard 'Analyze Document' node in n8n has limited options. By using the Gemini API directly, you gain access to 'hidden settings' and more granular prompt control for higher data output accuracy.
The Advantage of Multimodal AI
Gemini is highly effective for this task because it is multimodal—it can 'see' the visual layout of an invoice. Even if invoice formats vary (different layouts), the AI can still locate the 'Total Amount' without needing to set specific coordinates like traditional extraction software.
Prompts
Structured Invoice Data Extraction
Target:
Gemini API
Extract the following fields from the attached invoice PDF: invoice_sender, sender_address, invoice_number, invoice_date, total_amount, and currency. Requirements:
- Return the data in a clean JSON format.
- Ensure the date is in YYYY-MM-DD format.
- If a field is missing, return 'N/A'.
- Identify the currency symbol and convert it to the 3-letter ISO code (e.g., EUR, USD).
Step by Step
How to Set Up an n8n Invoice Automation Workflow
- Create a dedicated Google Drive folder to store invoice PDF files.
- Set up a Google Sheets file with these column headers: Invoice Sender, Address, Invoice Number, Date, Total Amount, and Currency.
- In n8n, add a 'Google Drive' node and set it to 'Watch for New Files' to trigger whenever a new PDF is uploaded.
- Use a second 'Google Drive' node with the 'Download File' action to retrieve the PDF's binary data.
- Add a 'Google Gemini' node and select a model that supports document processing (such as Gemini 1.5 Pro/Flash).
- Connect the 'Gemini API' using a valid API Key from Google AI Studio.
- In the Gemini node configuration, upload the PDF file as input context.
- Write a structured prompt to instruct Gemini to extract data in JSON format (refer to the Prompt Card).
- Add an 'Edit Fields' (Set) node to map the JSON output from Gemini into the appropriate data format.
- Add a 'Google Sheets' node with the 'Append Row' action to insert the extracted data into a new row.