Your first n8n automation: a step-by-step walkthrough
Most n8n tutorials either stop at "hello world" or jump straight to a 40-node agent. This one builds a single useful workflow end to end: invoices arrive by email, AI reads them, the important ones get logged and flagged. By the end you will understand triggers, credentials, test runs, expressions, branching and activation well enough to build the next one on your own.
What we are building
Here is the workflow in one sentence: when an email arrives in a Gmail inbox, an AI model decides whether it is an invoice and pulls out the supplier, amount and due date; if it is an invoice, the details are added as a row in a Google Sheet and a message goes to a Slack channel.
That is five nodes. It is small enough to finish in an afternoon and real enough that you could switch it on at work next week. The same shape (trigger, AI step, decision, record, notify) covers a surprising share of office automation, so once you have built it, you have a template for dozens of others.
Not on Gmail or Slack? n8n has Outlook, Teams and Excel nodes. The steps are the same.
Before you start: Cloud or self-hosted?
n8n comes in two main forms. You can use the hosted version, n8n Cloud, which runs in your browser with nothing to install. Or you can run n8n yourself, on your laptop or a server, because it is open source (under a "fair-code" license; check the current terms if you plan to use it commercially).
| n8n Cloud | Self-hosted | |
|---|---|---|
| Setup time | Minutes. Sign up and open the editor. | Longer. You install and maintain it. |
| Cost | Paid plans after any trial. Check current pricing. | Software is free to run; you pay for the server. |
| Maintenance | Handled for you. | Updates, backups and uptime are your job. |
| Data location | On n8n's infrastructure. | On your machine or your company's server. |
| Best for | Your first workflows, small teams. | Strict data rules, heavy volume, tinkerers. |
For a first build, Cloud is the faster path. If you want to try self-hosting on your own computer and you have Docker installed, the n8n documentation gives a one-line command that looks roughly like this (check the docs for the current version, because flags and image names can change):
docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
Then open http://localhost:5678 in your browser. Keep in mind that a workflow running on your laptop stops when your laptop sleeps. For anything that has to run while you are away, use Cloud or a proper server.
The nodes we will use
In n8n, every step is a "node." Data flows from left to right, from one node to the next, as a list of items. Each item is a small JSON object, which is just a set of named fields like subject or from.
| Step | Node | What it does here |
|---|---|---|
| 1 | Gmail Trigger | Checks the inbox on a schedule and starts the workflow for each new email. |
| 2 | AI step (for example a Basic LLM Chain with a chat model attached, or a direct OpenAI or Anthropic node) | Reads the email and returns structured fields: is it an invoice, supplier, amount, due date. |
| 3 | IF | Sends invoices down the "true" branch and everything else down "false." |
| 4 | Google Sheets | Appends a row with the extracted details. |
| 5 | Slack | Posts a short message to a channel so a person knows it arrived. |
Node names shift a little between n8n versions. If you cannot find one by the exact name above, open the node panel (the plus button on the canvas) and search for the app name instead.
Step by step
- Create a new workflow. From the n8n home screen, create a workflow and give it a clear name, such as "Invoice inbox to sheet." Good names matter once you have twenty of these.
- Add the trigger. Click the plus button and search for "Gmail." Choose the Gmail Trigger and the event for a new message received. Set the poll interval to something sensible, like every five or fifteen minutes. Every workflow needs exactly one way to start; this is it.
- Connect your credentials. The trigger will ask for a Gmail credential. On n8n Cloud this is usually a sign-in button that walks you through Google's permission screen. On a self-hosted install you may need to create OAuth credentials in Google Cloud first; the n8n docs have a page for each app. Credentials are saved once and reused by any node that needs them.
- Narrow the trigger. You do not want every newsletter going through an AI model. Use the trigger's filter options (or a Gmail search query, if your version offers one) to limit it, for example to emails with attachments or emails sent to a specific invoices address.
- Fetch a test event. Send yourself a sample invoice email, then click the button on the trigger node to fetch a test event. Depending on your version it may be labeled "Fetch test event," "Test step" or "Execute step." You should see the email appear in the output panel on the right, with fields like
subject,fromand the text of the message. - Pin the test data. In the output panel, look for the pin icon and click it. Pinning saves this sample so later test runs reuse it instead of checking the inbox again. This makes testing faster and stops you from needing a fresh email each time.
- Add the AI step. Add a node after the trigger. A common choice is the Basic LLM Chain node with a chat model sub-node attached (OpenAI, Anthropic and others are available). Add the credential for your chosen model provider, which normally means pasting an API key. Then write the prompt (see the next section).
- Ask for structured output. Turn on the option that requires a specific output format if your node offers it, or attach a Structured Output Parser, so the model returns clean fields rather than a paragraph. If neither is available, ask for JSON in the prompt and parse it in the next step.
- Test the AI step. Run just this node. Check the output. Does it correctly say this is an invoice? Did it get the amount right? Change the prompt and rerun until it is reliable on your sample. Then try two or three different emails, including one that is clearly not an invoice.
- Add the IF node. Add an IF node after the AI step. Set the condition to check the field the model returned, for example that
is_invoiceis true. The IF node now has two outputs: true and false. - Add Google Sheets on the true branch. Drag from the true output and add a Google Sheets node with the operation to append a row. Pick your spreadsheet and sheet. Map each column to a value from the AI step using expressions (explained below).
- Add Slack after the sheet. Add a Slack node to send a message to a channel. Write a short message using expressions, such as the supplier and amount, plus a link to the sheet.
- Decide what happens on false. You can leave the false branch empty, which means non-invoices are ignored. Or add a small step that labels the email in Gmail so you can review what was skipped.
- Run the whole workflow. Use the main button at the bottom of the canvas. It may be labeled "Test workflow" or "Execute workflow" depending on your version. Each node shows a green check or a red warning. Click any node to see exactly what went in and what came out.
- Activate it. When it works, unpin the test data, save, and switch the workflow on with the active toggle at the top of the editor (newer versions may use a publish or activate button instead). From now on it runs on its own, and every run appears in the Executions list.
The prompt
The AI step is only as good as its instructions. Be specific, give it the exact fields you want back, and tell it what to do when information is missing. Here is a prompt you can adapt:
You read incoming business emails and decide if they are supplier invoices.
Email subject: {{ $json.subject }}
Email from: {{ $json.from }}
Email body:
{{ $json.text }}
Return JSON only, with these fields:
- is_invoice: true or false
- supplier: the company name sending the invoice, or "" if unknown
- amount: the total amount due as a number, no currency symbol, or null
- currency: three-letter code such as USD or HKD, or ""
- due_date: in YYYY-MM-DD format, or "" if not stated
- confidence: "high", "medium" or "low"
Rules:
- Do not guess numbers. If the amount is not clearly stated, use null.
- Receipts for payments already made are not invoices.
- Marketing emails are not invoices.
The field names in your email data may differ slightly, such as text versus textPlain or snippet. Look at the pinned trigger output and use whatever names you see there.
Expressions, explained
The double curly braces in that prompt are n8n expressions. They let you drop data from earlier nodes into any field.
{{ $json.subject }}means "thesubjectfield of the item coming into this node."{{ $('Gmail Trigger').item.json.from }}means "thefromfield from the node named Gmail Trigger," which is useful when you need data from a node further back.{{ $now }}gives the current date and time, handy for a "logged at" column.
You rarely need to type these from memory. In most fields you can switch to expression mode and drag a field from the input panel on the left straight into the box. n8n writes the expression for you and shows a live preview of the result underneath, which is the fastest way to catch mistakes.
Note on the AI output: depending on how your AI node returns data, the fields may sit directly on $json or inside a wrapper such as $json.output. Check the output panel and adjust your expressions in the IF, Sheets and Slack nodes to match.
Handling errors
An automation that fails silently is worse than no automation, because people stop checking the thing it replaced. Three habits fix most of this:
- Set an error workflow. Build a second small workflow that starts with the Error Trigger node and sends you a Slack message or email with the workflow name and error. Then, in your main workflow's settings, choose it as the error workflow. Any failure now reaches you.
- Use the low-confidence path. Add a second condition so that invoices with
confidenceset to "low" go to a person for review instead of straight into the sheet. - Check Executions weekly. The Executions list shows every run. A two-minute weekly look catches drift, such as a supplier who changed their email format.
Common errors and fixes
| What you see | Likely cause | Fix |
|---|---|---|
| Credential or authorization error | Expired sign-in, missing permission scope, or a wrong API key. | Reconnect the credential. Check that the account has access to the specific sheet or channel. |
| Expression shows as empty or undefined | The field name does not match the actual data, or it is nested one level deeper. | Open the input panel, find the real field, and drag it in rather than typing. |
| AI returns text instead of JSON | No output format enforced. | Use a structured output option or parser, and say "Return JSON only" in the prompt. |
| IF node sends everything to false | Comparing the text "true" to a boolean true, or the wrong field path. | Match the data types in the condition, or convert the value first. |
| Workflow ran in testing but not live | Still pinned data, or the workflow is not active. | Unpin, save, and confirm it is switched on. |
| Duplicate rows in the sheet | The same email processed twice after edits or restarts. | Add a message ID column and check for it before appending. |
A note on privacy
This workflow sends email content to an AI provider. Before you switch it on with work data, check three things: your company's policy on using AI tools with internal and supplier data, the data-handling terms of the model provider and plan you are using, and who in your organization needs to approve new connections to company accounts. Where possible, use a company-approved account rather than a personal API key, and avoid sending more data than the task needs. If your rules are strict, self-hosting n8n and choosing a provider your IT team has approved is often the path that gets a yes.
Where to go next
Swap the Gmail Trigger for a form trigger or a schedule and the same pattern handles expense claims or a weekly report. Use a Switch node instead of IF to sort emails into several categories.
If you are still deciding which platform to learn, our comparison of n8n, Zapier and Make covers when each one fits best.
FAQ
Do I need to know how to code to use n8n?
No. Everything in this walkthrough is point and click, plus short expressions you can create by dragging fields. Code nodes exist for when you want them, but they are optional.
Which AI model should I connect?
Use whichever one your company has approved. For extraction tasks like this one, most current models from the major providers do well when the prompt is specific. Test with your own emails and compare.
How much does running this cost?
It depends on your n8n plan or server, plus the AI provider's usage charges, which scale with how many emails go through the AI step. Filtering the trigger so only likely invoices reach the model keeps this down. Check each provider's current pricing.
Can I use Outlook and Teams instead?
Yes. n8n has Microsoft Outlook, Excel and Teams nodes. The workflow shape is identical; only the trigger, sheet and notification nodes change.
What if the AI gets a number wrong?
Assume it sometimes will. That is why the prompt says not to guess, why there is a confidence field, and why low-confidence results go to a person. Treat the sheet as a draft that saves typing, not as the final ledger, until you have checked a few weeks of results.
Build this on your own work, live
In the AI for Automation track, session 4 goes deeper with n8n: branching, error handling and schedules, built on your real tools rather than a demo inbox. Eight live sessions over four weeks, about 3 hours a week live, starting January 2027 in Hong Kong, the US and Southeast Asia. Not sure yet? Try a free 60-minute live session first.
Apply for January 2027Book a free 60-min session