Monthly e-invoices through Poland's KSeF API

A scheduled script that issues the same invoice every month through Poland's mandatory e-invoicing system, encrypts it, files the receipt and emails the PDF.

Problem
KSeF, Poland's national e-invoicing system, became mandatory in 2026. A recurring invoice meant logging into a government app every month to type the same thing.
What runs
On the 5th of each month at about 08:00: build, encrypt, submit, wait for the official receipt, archive, email.
How it is watched
Every run leaves the XML, the official receipt (UPO) and the API result in Google Drive. A failed scheduled run emails the owner.
Stack
Google Apps Script, KSeF API 2.0, node-forge for the cryptography, Drive, Gmail.
Code
Open source on GitHub

The problem

Some invoices never change: the same buyer, the same line items, the same amount, once a month. Under KSeF each one still has to be built in the official FA(3) schema and submitted to the tax authority's API before it legally exists. Doing that by hand twelve times a year is exactly the kind of work that gets forgotten on the one month it matters.

What it does

  • Builds the invoice XML in the FA(3) schema, with the invoice number generated from a pattern such as FS/{MM}/{YYYY}.
  • Authenticates to KSeF with a token, encrypts the invoice (RSA-OAEP SHA-256 and AES-256-CBC, which Apps Script lacks natively, hence node-forge) and submits it in an online session.
  • Polls for status and downloads the UPO, the official confirmation that the invoice was received.
  • Generates a PDF and emails it to the buyer.
  • Runs against KSeF's test or demo environment until you switch it to production.

How it stays under control

The proof of each run is the receipt, not a log line: XML, UPO and the raw API response are saved to a Drive folder per run, so an accountant can check any month without asking anyone. Apps Script emails the account owner when a scheduled run fails.

It runs on a Google account the business already has. There is no server to pay for or patch.

What a business could reuse from this

E-invoicing mandates are spreading across the EU. The same pattern fits any government or partner API with a strict schema and signed submissions: build, encrypt, submit, keep the receipt, report.

Want something like this, built around your process?

Tell me what happens today and how often. A few sentences are enough.

Describe a process