Bank statements from the inbox to Google Drive with n8n: the daily flow we actually run

How we file bank statements from four banks and a payment provider into the right Drive folders with one n8n run a day: sender rules, idempotent uploads, labels as a queue, and the Drive 403 that retries did not fix.

Published · 6 min read · Flowsmith editorialn8nautomationaccounting

A slim stack of blank paper statements glides along a thin blue line of light into an open dark filing drawer with neat empty folders.
Illustration drawn for this article. No text in the image, so it works in every language.
In short
  • Statements from four banks and a payment provider arrive by e-mail. One n8n run a day files every attachment into the right Google Drive folder for the accountant and the import into the accounting software.
  • The rules are simple and boring on purpose: bank by sender, account by file name, skip if the same file is already there, never rename, never delete.
  • Gmail labels are the queue: done, error, and a retry is removing the error label.
  • The one real incident was a Drive 403 on the last uploads of a batch. The node's built-in retry did not run, and an explicit second attempt did.

Every company that has more than one bank account knows the chore: statements arrive by e-mail as PDF, GPC or a zipped bundle, and somebody has to save each one into the right folder before the accountant can book it. It takes a few minutes a day, it is easy to forget, and a missing statement shows up weeks later as a question from the accountant.

We replaced a paid scenario in another automation tool with a small n8n workflow. This article describes what it does, the decisions behind it, and the one failure that taught us something about retries.

The shape of the flow

The workflow has five steps and no cleverness:

  1. Schedule. It runs once a day at 03:00 UTC. A manual trigger and a protected webhook exist for the rare day when someone needs it now.
  2. Fetch. A Gmail node searches the mailbox for messages with the label statements that do not yet carry statements/done or statements/error, and downloads their attachments.
  3. Decide. A Code node turns every attachment into a list of uploads: which folder, which file name. One attachment can produce two uploads.
  4. Upload. A Google Drive node uploads what is not there yet.
  5. Mark and report. Each message gets the done or the error label. A short report goes to our agent coordination board only when something was uploaded or failed.

A daily schedule instead of a trigger on every new e-mail matters more than it looks. Statements are not urgent, and a single run a day costs roughly thirty executions a month. Polling every few minutes would cost thousands and fill the execution log with empty runs that hide the interesting ones. If you are deciding where to run n8n, our n8n Cloud or self-hosted article explains why execution counts drive that choice.

The rules: sender, file name, folder map

Each bank behaves differently, so the decision step starts with the sender. Our group forwards statements through a shared address, so the flow checks both the sender and the reply-to header.

  • One bank puts the account number and the currency into the attachment name, separated by underscores, and sends GPC files zipped. The flow unpacks the zip and files the GPC twice: into the account's folder and into a central folder that the accounting software imports from.
  • Another bank puts the account number at the start of the file name.
  • A third sends only PDF statements, and a payment provider puts the currency into the subject line instead of the file name.
  • Signature files and inline images are ignored.

The account-to-folder mapping lives in one constant inside the workflow and in a JSON file in our git repository. A new bank account means changing both in one pull request. That is deliberate: the map is the part a human must be able to read and approve.

Idempotent by design

The most important property of a filing flow is that running it twice changes nothing. Before every upload the flow searches the target folder for a file with the same name. Same name and same size means it is already there and the upload is skipped. Some banks send the same statement more than once in a day, so duplicates inside one batch are removed as well.

The flow never renames a file and never deletes anything. If the accountant has moved or edited something on Drive, the automation does not fight them.

We tested this on real data before switching on uploads. With the upload and label steps disabled, the flow read 35 messages from the previous days, which had meanwhile been filed by hand: 50 file-to-folder pairs, all 50 recognised as already present, zero errors, zips unpacked correctly. Only then did the scheduled run start uploading.

Labels as the queue

The flow keeps no database of its own. The mailbox is the state: a message without a result label is waiting, done means filed, error means look at me. A failed message is not picked up again by the next run, so one broken file cannot block the queue. A person who has fixed the cause removes the error label, and the next run tries again.

The report to our agents carries counts and message IDs, never account numbers. A failure of the whole run goes to n8n's error workflow, which alerts us separately. This is the same pattern we describe in human-in-the-loop automation: the machine does the routine and leaves visible traces where a person needs to look.

The incident: Drive 403 on the last uploads

The day after go-live, one statement kept ending with the error label while all the others went through. The n8n log showed Forbidden, perhaps check your credentials?, which is Drive returning HTTP 403. File name, folder and permissions were all fine, and the same file uploaded at once when we tried it in a small batch at midday.

The pattern became clear when we lined up two days of runs: it was always the last two uploads of the batch, about forty seconds into the run, after roughly a dozen uploads in a row. The failing statement simply happened to be the oldest message and therefore always the last. Drive was refusing a burst, not a file.

The first fix was to switch on the node's Retry on fail. It did nothing, and the reason is worth knowing: the node was also set to continue on error, so it caught the failures item by item and never raised an error. n8n retries only when a node fails. The node did not fail, it returned failed items, so no retry ever ran.

The working fix is an explicit branch after the upload: take only the failed items, wait 45 seconds, check again whether the file exists (the first attempt may have created it and failed afterwards), and upload whatever is still missing. A message gets the error label only when the second attempt fails too, and the report now counts how many files needed it.

What we would tell you to copy

  • Run on a schedule unless the job is truly urgent. It is cheaper and easier to read.
  • Make the flow idempotent first, then test it on data that has already been filed by hand.
  • Keep the mapping in one readable place and in version control.
  • Use labels or a status field as the queue so failures are visible and retries are one click.
  • Do not trust a retry setting you have not seen work. Check in the log that it actually waited and tried again.

If you want to learn to build flows like this, start with the free Academy lesson on when failure looks like success. It covers exactly the kind of silent error that the retry setting hid from us.

Frequently asked questions

Can n8n save e-mail attachments to Google Drive automatically?

Yes. A Gmail node fetches the messages with their attachments, a Code node decides the target folder for each file, and a Google Drive node uploads it. The work is in the rules: which bank sent it, which account it belongs to, and what to do when the file is already there.

Should the flow react to every new e-mail?

For statements, no. Banks send them once a day or less, so one scheduled run a day is enough. It costs about thirty executions a month instead of thousands of polling checks, and it is easier to read in the log.

How do you avoid uploading the same statement twice?

Before each upload the flow looks for a file with the same name in the target folder. Same name and same size means it is already there, so it is skipped. Duplicates inside one batch are dropped too, because some banks send the same statement more than once.

What happens when an upload fails?

The message gets an error label instead of the done label, so nothing is lost and the next run does not pick it up by accident. Removing the error label is the retry. Transient Drive errors get one automatic second attempt after a pause.

Written from our own production systems by the Flowsmith editorial team, with AI assistance.

Want this running in your company?

Flowsmith designs and operates automations like this for small and mid-sized teams — with a person approving anything that leaves the building.

More from the blog