Category: Automations › Gmail & Inbox Automation · Best for: Accounts teams collecting invoices and bills · Platform: n8n · Steps: 14
What it does
Files sent to your Gmail go into Google Drive and get listed in a sheet.
Large language models are perfect for data extraction tasks as they can work across a range of document layouts without human intervention. The extracted data can then be sent to a variety of datastores such as spreadsheets, accounting systems and/or CRMs.
Works with: Gmail, Lm OpenAI, Output Parser Structured, Chain Llm, Google Sheets, Google Drive
What you get
- The n8n workflow file (
workflow.json), ready to import - This setup guide
- The list of fields to change for your own accounts (see Install below)
- Email support if you get stuck
Before you start
-
An n8n account. Easiest: n8n Cloud (free trial). Self-host for free with Docker:
docker run -it --rm -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n, then open http://localhost:5678. -
Accounts and API keys for these services:
- Google (Sheets, Gmail, Drive, Calendar, Docs): how to connect (used by Gmail Trigger1, Upload PDF to Drive1, Rename file1, Move to the correct folder1, Gmail, Google Drive, Append to Reconciliation Sheet)
- OpenAI API key: how to connect (used by OpenAI Model)
Install
- In n8n, click Create workflow (top right).
- Click the ⋯ menu → Import from file and choose
workflow.json. Or open the file, copy everything and paste it onto the empty canvas with Ctrl/Cmd + V. - Open each node with a red warning triangle and pick or create the matching credential from the list above.
- Point these fields at your own sheets, chats and accounts:
- Move to the correct folder1 →
driveId: choose your own - Move to the correct folder1 →
folderId: choose your own - Append to Reconciliation Sheet →
sheetName: choose your own - Append to Reconciliation Sheet →
documentId: choose your own
- Move to the correct folder1 →
- Click Save.
Test it
- Click Test workflow (or Execute workflow). Gmail Trigger1 starts it. Trigger it once with real sample data.
- Click each node to check its output. A green tick means the step worked.
- Fix any red node: it's almost always a credential or a field that still points at a sheet or chat that isn't yours.
Go live
Toggle Active (top right). From now on it runs on its own. Check Executions in the left sidebar to see every run.
How it works, step by step
- Gmail Trigger1 starts the workflow (Gmail).
- OpenAI Model uses AI (Lm OpenAI).
- Structured Output Parser uses AI (Output Parser Structured).
- Setup1 reshapes the data for the next step.
- Apply Data Extraction Rules uses AI (Chain Llm).
- Only invoice mails with attachments checks a condition and routes items accordingly.
- Map Output reshapes the data for the next step.
- Upload PDF to Drive1 calls an external API (https://www.googleapis.com/upload/drive/v3/files).
- Gmail uses Gmail to markAsRead.
- Append to Reconciliation Sheet uses Google Sheets to append.
- Rename file1 uses Google Drive to update.
- Move to the correct folder1 uses Google Drive to move.
- Google Drive uses Google Drive to download.
- Extract from File2 uses Extract From File to pdf.
Extra setup notes
These notes are also on the canvas as yellow sticky notes:
Setup
- Setup your Gmail and Google Drive credentials
- Setup your Google Sheets credentials
- Setup your Openai api key
3. Use LLMs to Extract Values from Data
Read more about Basic LLM Chain
Large language models are perfect for data extraction tasks as they can work across a range of document layouts without human intervention. The extracted data can then be sent to a variety of datastores such as spreadsheets, accounting systems and/or CRMs.
Tip: The "Structured Output Parser" ensures the AI output can be inserted to our spreadsheet without additional clean up and/or formatting.
Need more attributes? Change it here!
Troubleshooting
- "Credentials not found": open the node and select your credential again.
- Google "access blocked": in Google Cloud, add your email as a test user on the OAuth consent screen.
- Webhook not firing: copy the node's Production URL (not Test URL) into the other app, and make sure the workflow is Active.
- AI node errors: check your API key has billing enabled and the model name exists on your plan.
- Nothing happens on schedule: the workflow must be Active, and self-hosted n8n must stay running.
Need help?
Reply to your Morning Method order email and we'll help you get it running.
© Morning Method