# A supplier invoice in one minute > How we went from an hour or two per supplier invoice to about a minute: Fortnox's API, an open-source MCP server with our own rules enforced in code, and an agent that uses the web interface for the one step the API cannot do. By Codegility, 2026-11-28. Drafted with AI agents, reviewed and approved by a human. Bookkeeping is repetitive, and it does not forgive mistakes. Nobody at Codegility is an accountant, so booking a supplier invoice in Fortnox used to take an hour, sometimes two. A month is long enough to forget how it was done last time, and most of that hour went into opening old vouchers and copying what they did. Our invoices make it harder. Most suppliers are in the USA and Ireland, a few in Sweden. They bill in dollars, and the company card turns that into kronor at its own rate. Fortnox has its own interpretation of supplier invoices, and it does well on the Swedish invoices it was built for. Ours were a different shape: an American invoice, a receipt, and a card statement in kronor that together make one purchase. Its interpretation could not put those together correctly, so they were booked by hand. Today a supplier invoice takes about a minute of a person's attention. ## What it looks like now Three files go into a chat with Claude: the invoice, the receipt, and the card statement that shows what the purchase cost in kronor. Then one line: ![The prompt: three PDF files attached, the invoice, the receipt and the card transaction, and the words "Bokför i test".](/blog/bookkeeping-with-an-agent/prompt.webp) "Bokför i test" books it in a test company. "Bokför i prod" books it in the real books. The assistant reads the files and comes back with a plan before it writes anything: the supplier invoice and the payment, each with its booking date, description and the accounts every amount goes to. This one is from the test company, with the amounts, the invoice number and the card hidden: ![The assistant's plan in Swedish: a supplier invoice in series D with its booking date, description and VAT type, debiting 4531 and 2645 and crediting 2614 and 2440, and a payment in series E debiting 2440 and crediting 2493. Amounts, the invoice number and the card's name are hidden.](/blog/bookkeeping-with-an-agent/plan.webp) It ends with "Svara "ok" så lägger jag upp och bokför": answer "ok" and I will register and book it. This is where the language model earns its place. Claude Opus reads the three documents the way a person would. It finds the invoice number and the period on an invoice that follows no Swedish standard, sees that the dollar amount on the receipt is the same purchase as the kronor amount on the card statement, and books the kronor amount actually paid. It recognises a service bought from outside the EU and applies reverse-charge VAT. None of that needs a fixed invoice layout, which is why our foreign invoices, registered in kronor at the amount the card was charged, now go through exactly like Swedish ones. The answer is "ok": a yes to exactly that plan, these two vouchers on these accounts, and nothing else. The assistant registers the invoice, attaches the documents, and books the invoice and the payment. It then shows the voucher texts it will set in the web interface, saves them after another yes, and checks the result. Between the two yeses we do something else. ## The pieces ![The setup: the open-source Fortnox MCP server is merged into a private company copy that adds our rules and instructions. Claude uses it against a test company and the real books, and Claude in Chrome sets texts in the Fortnox web interface.](/blog/bookkeeping-with-an-agent/setup.svg) - **Fortnox**, a Swedish cloud accounting system with a REST API. At the time of writing Fortnox offers no MCP server of its own, and its API needs a separate developer account, which we pay for on top of the bookkeeping subscription. That account has one benefit we would not want to be without: [sandboxes](https://www.fortnox.se/developer/developer-portal), test companies where a new flow can be tried without any risk of messing up the real books. - **An open-source MCP server for Fortnox**, [erp-mafia/fortnox-mcp](https://github.com/erp-mafia/fortnox-mcp). The Model Context Protocol lets an assistant call an external system through a set of tools. The server exposes the Fortnox API that way, but it was mostly read-only: list invoices, read vouchers, run reports. - **Claude Desktop** runs the bookkeeping assistant. It is connected to the server twice: once to the real books, and once to a test company, each with its own login. - **Claude Code** does the development: code, reviews and pull requests. - **Claude in Chrome** does the one step the API cannot (below). ## Open source in, company rules on top Booking needs writing: registering supplier invoices and payments, uploading documents, linking them. Those are general features any Fortnox user could want, so they are built as general improvements to the open-source server, with made-up data and their own tests, and offered back to the project. Our company copy of the server merges that public code and adds a thin layer of its own. Code flows one way only. Nothing in the company copy, which holds supplier names, invoice numbers and amounts in its history, ever goes back. A few guards make that hold even on a careless day: - **A push guard.** A git hook, turned on once in every clone of the company copy, refuses any push to anywhere but the company copy itself. - **A layer check in CI.** It compares the company copy with the public code it was last merged from, and fails if anything outside the company layer differs. "The rest is identical to the public code" is checked on every pull request. - **Merge commits only.** One squash merge once dropped the link to the public code, and the layer check compared against the wrong base. Squash and rebase are now switched off. ## Rules in code, not only in prompts The company layer wraps the server's tool registration: one call, made before any tool is registered. The public tool code is never edited. Selected tools get a check that runs before the call reaches Fortnox, and if the check fails, or cannot run, the call is refused. The rules in general terms: - A supplier invoice must have its invoice number, and its rows a row text in a fixed format that contains it. - Nothing is booked until its source document is linked. - No manual vouchers in the series that belong to supplier invoices and payments. A made-up example: the assistant registers an invoice from Acme AB (supplier 1) and leaves the invoice number out of the row text. ```json { "supplier_number": "1", "invoice_number": "INV-1001", "currency": "SEK", "total": 1250, "vat": 250, "rows": [{ "account": 6540, "debit": 1000 }], "row_text": "acme - hosting - dec 2026" } ``` The server answers before anything reaches Fortnox: ```text row_text "acme - hosting - dec 2026" does not follow the Codegility format ' - - ', e.g. 'acme - 12345 - hosting 2026-2027' with "INV-1001" as the middle part. ``` Every rule has a test, and so does the wiring: a test fails if a public update renames a tool the layer wraps, or adds a tool that writes to supplier invoices, supplier payments or vouchers without being wrapped or deliberately put on an allow-list. A prompt can be misread. A refused call cannot. ## The instructions, served by the server What cannot be checked mechanically is written down once: the voucher series, the accounts for each kind of purchase, the modes of payment, the naming standard for voucher texts, and the workflow step by step. These instructions live in the company copy and are served by the server itself, as a tool the assistant calls before it proposes anything. Changing a rule is a reviewed pull request, and the next session follows it. Here is their structure, translated from Swedish and shortened. The accounts are the standard Swedish (BAS) accounts every company uses; suppliers, banks and numbers are replaced: ```markdown #### Voucher series | Series | Used for | |--------|-------------------| | A | General entries | | D | Supplier invoices | | E | Supplier payments | | M | VAT report | #### Chart of accounts (excerpt) | Account | Name | |---------|--------------------------------------------------------| | 1930 | Företagskonto (business bank account) | | 2440 | Leverantörsskulder (accounts payable) | | 2493 | Kortfristiga skulder, företagskort (company card) | | 2614 | Utgående moms, omvänd betalningsskyldighet, 25 % | | 2641 | Debiterad ingående moms | | 2645 | Beräknad ingående moms på förvärv från utlandet | | 2893 | Skulder till närstående personer (private outlay) | | 4531 | Inköp av tjänster från ett land utanför EU, 25 % moms | | 4535 | Inköp av tjänster från annat EU-land, 25 % | | 6540 | IT-tjänster | Ask before proposing any other series or account. That is fine, but I approve it first. #### When you present a voucher or a proposal - Always show the account's name next to its number, and the booking date. - Always show the description in the naming standard, e.g. "faktura (1) - acme - INV-1001 - nov 2026". The number is allocated when the invoice is registered: show it as the expected number. #### Posting per supplier (series D, credit accounts payable = invoice total) | Supplier | Posting | |------------------------|------------------------------------------| | Acme AB (Sweden) | 6540 net + 2641 VAT 25 % | | Example Ltd (EU) | 4535 + 2645/2614 reverse-charge VAT 25 % | | Example Inc. (non-EU) | 4531 + 2645/2614 reverse-charge VAT 25 % | #### Modes of payment | Mode | Account | |----------------|---------| | Bank | 1930 | | Company card | 2493 | | Private outlay | 2893 | #### Naming standard for vouchers `type (nr) - supplier - invoice no - period` - (nr) is Fortnox's number for the supplier invoice, the same on D and E, so the pair belongs together. Lower case except invoice numbers. - Every row gets the row text "supplier - invoice no - period". - Fortnox's default texts are overwritten. #### Workflow: supplier invoice (D) and payment (E) Try new flows in the test company first. Check the company name before every write. Never write in the real books without the owner's approval. 1. Register the supplier invoice unbooked, link its document, and show it. 2. Book it after explicit approval of that action. 3. Register the payment with the right mode of payment, show it, book it after approval. 4. Set the texts in the web interface with Claude in Chrome. Change texts only, never accounts, amounts or dates. Save after approval. 5. Read both vouchers back through the API and check texts and balance. 6. Report the voucher numbers and texts. #### The tools in the Fortnox server The server refuses calls that break these rules, before anything reaches Fortnox. - Supplier invoice: always an invoice number; rows carry the row text. - No booking without a linked document. No manual vouchers in series D or E. - Booking, cancelling, deleting, crediting and manual vouchers need explicit approval of that exact action, every time. Booking cannot be undone. ``` The workflow, in short: 1. Register the invoice unbooked, with its rows, VAT type and row text, and link the PDF. 2. Show the plan for the invoice and its payment, and book only after an explicit yes to exactly that plan. 3. Register the payment with the right mode of payment, and book it as planned. 4. Set the voucher texts in the web interface (below). 5. Read both vouchers back through the API and check the texts and the balance. **A person approves every irreversible step.** Booking cannot be undone through the API, so nothing is booked, cancelled, credited or entered by hand without an explicit yes to exactly that action, every time. A yes covers what was shown, and nothing more. **A test company first.** The developer account's sandbox is a complete test company, and new flows run there before they touch the real books. That found real bugs that tests with made-up data had not: a payment list without its mode of payment, a cryptic Fortnox error instead of a plain refusal, a check that read whichever financial year Fortnox returned first. Each was fixed in the open-source code first. ## The last mile: an agent at the keyboard We name every voucher by a standard, so that a glance at the list says what it is, and the invoice and its payment share a number. Fortnox's API books vouchers with its own default texts, and has no way to change them afterwards: ![The voucher list with Fortnox's default descriptions, "Levfakt GitHub, Inc." and "Levbet GitHub, Inc.".](/blog/bookkeeping-with-an-agent/default-texts.webp) So the assistant does what a person would do. With Claude in Chrome it takes over a browser tab where we are already logged in to Fortnox, opens each voucher, clicks Ändra, and types the description and the text on every row. It shows the new texts and saves only after a yes. It changes texts only, never accounts, amounts or dates, and then reads the vouchers back through the API to check them. ![Fortnox in a Chrome tab that Claude controls ("Claude is working here"), editing the description of a supplier invoice voucher, with the invoice beside it. Account numbers, amounts and identifiers are hidden.](/blog/bookkeeping-with-an-agent/voucher-in-chrome.webp) ## What changed | | Before | Now | |---|---|---| | Time per supplier invoice | one to two hours | about a minute of attention | | How it was done last time | old vouchers, compared by hand | written down once, served by the server | | Invoices in dollars | by hand | in kronor, like Swedish ones | | Voucher texts | Fortnox's defaults | our naming standard, every time | | A mistake | found later, if at all | refused by the server, or caught at the "ok" | ## What we learned - **Separate with guards, not good intentions.** A push guard and a layer check beat "be careful what you commit". - **The merge method matters.** A single squash merge broke the link the whole update flow depends on. - **Put hard rules in code.** Wrapping the tool registration gives us company rules without changing the public code, so public updates still merge cleanly. - **Test against a real but separate company.** Made-up data proves the code; a sandbox company shows what Fortnox actually returns. - **Keep a person on the irreversible steps.** The assistant drafts, registers and checks. A person says yes to anything that books. The assistant is not an accountant either. What makes this safe is the structure around it. ## What comes next Much of this may soon come built in. On 16 November 2026 Fortnox announced that it will invest SEK 5 billion over the next five years in AI, infrastructure and technology ([SVT](https://www.svt.se/nyheter/lokalt/smaland/vaxjobaserade-fortnox-varslar-200-tjanster)). Its chief executive described it as "moving from using AI to building Fortnox entirely around AI" ([Sweden Herald](https://swedenherald.com/article/fortnox-to-invest-sek-5-billion-in-ai-lay-off-200-employees)). We are sure its own invoice interpretation will improve with that, foreign invoices included, and that the gap we filled ourselves will shrink. Until then, this works today. --- *Codegility is not affiliated in any way with Fortnox, or with Anthropic, the maker of Claude, and this post is not an endorsement of either. It describes how we bought back time for what matters to us: building our own SaaS products.* --- © 2026 Codegility AB. All rights reserved.