From your systems to a dashboard

A dashboard that reads straight from the accounting system breaks when the API changes and cannot show history. Put a small database in between. Here is the recipe, with code we ran on 19 November 2026.

Last checked:

ChecklistWhat we tripped over ourselves
  • Test on the real database
  • Reconcile with the source
  • Dinero needs Pro
  • Shopify has two kinds of data
  • One contract instead of many connectors

The architecture: source → database → dashboard

Three layers, each with its own job. The sources are accounting (e-conomic, Dinero, Billy), the web shop (Shopify, WooCommerce) and the CRM. The database is a small PostgreSQL filled by a script every night. The dashboard only reads from the database: Data Studio, Metabase or Power BI.

Why not connect the dashboard directly? Because the sources differ. e-conomic uses two tokens, Dinero OAuth2 via Visma Connect, and Billy a static token. Dinero also requires both dates in a query on entries to be inside the same fiscal year, and allows 60 calls a minute for your own integration. A database gives you one place to collect it all, history over time, and a way to join sales with leads.

We have built integrations like this between e-conomic, Google Sheets and SQL for clients. If you would rather not write the adapters yourself, our own product JaKonto is one API over e-conomic, Dinero and Billy.

Step 1: Pull invoices from e-conomic

e-conomic has a demo agreement where both tokens are demo and you can only read. The script below fetches all booked invoices page by page (up to 1,000 per page) and writes them to PostgreSQL. You can run it again and again without duplicates, because the invoice number is the primary key. We ran it twice against the demo agreement and a PostgreSQL 17 in Docker: 6 invoices both times, no duplicates. The Danish variable names (alle_fakturaer = all invoices) are kept so the code matches the Danish page.

hent_fakturaer.py – run with DATABASE_URL set

import os
import requests
import psycopg

HEADERS = {
    "X-AppSecretToken": os.environ.get("ECO_APP_SECRET", "demo"),
    "X-AgreementGrantToken": os.environ.get("ECO_GRANT", "demo"),
    "Content-Type": "application/json",
}
START = "https://restapi.e-conomic.com/invoices/booked?pagesize=1000"


def alle_fakturaer():
    url = START
    while url:
        r = requests.get(url, headers=HEADERS, timeout=30)
        r.raise_for_status()
        data = r.json()
        yield from data["collection"]
        url = data["pagination"].get("nextPage")


with psycopg.connect(os.environ["DATABASE_URL"]) as conn:
    conn.execute("""
        CREATE TABLE IF NOT EXISTS invoices (
            number        int PRIMARY KEY,
            customer      int,
            inv_date      date,
            due_date      date,
            net_dkk       numeric(14,2),
            gross_dkk     numeric(14,2),
            remainder_dkk numeric(14,2),
            loaded_at     timestamptz DEFAULT now()
        )""")
    n = 0
    for f in alle_fakturaer():
        conn.execute("""
            INSERT INTO invoices (number, customer, inv_date, due_date,
                                  net_dkk, gross_dkk, remainder_dkk)
            VALUES (%s, %s, %s, %s, %s, %s, %s)
            ON CONFLICT (number) DO UPDATE
               SET remainder_dkk = EXCLUDED.remainder_dkk, loaded_at = now()""",
            (f["bookedInvoiceNumber"], f["customer"]["customerNumber"],
             f["date"], f["dueDate"], f["netAmountInBaseCurrency"],
             f["grossAmountInBaseCurrency"], f["remainderInBaseCurrency"]))
        n += 1
    print(n, "fakturaer indlæst")

With your own data you set ECO_APP_SECRET and ECO_GRANT as environment variables. Never put them in the code. Run the script every night with cron or a scheduled task.

Step 2: The KPIs in SQL

Once the data is in the database, the KPIs are ordinary queries. Note that receivables are calculated on the remaining amount. In e-conomic paid invoices otherwise look open. Column names are Danish: omsaetning is revenue, udestaaende outstanding, forfaldent overdue.

kpi.sql – revenue, outstanding and top customers

-- 1. Omsætning pr. måned (uden moms), antal fakturaer og kunder
SELECT date_trunc('month', inv_date)::date AS maaned,
       sum(net_dkk)                         AS omsaetning,
       count(*)                             AS fakturaer,
       count(DISTINCT customer)             AS kunder
FROM invoices
GROUP BY 1
ORDER BY 1;

-- 2. Udestående og forfaldent (inkl. moms, det er det, kunden skylder)
SELECT sum(remainder_dkk)                                         AS udestaaende,
       coalesce(sum(remainder_dkk) FILTER (WHERE due_date < current_date), 0) AS forfaldent,
       count(*) FILTER (WHERE remainder_dkk > 0
                          AND due_date < current_date)            AS forfaldne_fakturaer
FROM invoices;

-- 3. Top 5 kunder de seneste 12 måneder
SELECT customer, sum(net_dkk) AS omsaetning_12m
FROM invoices
WHERE inv_date >= current_date - interval '12 months'
GROUP BY customer
ORDER BY omsaetning_12m DESC
LIMIT 5;

On the demo data this gave 7,010.00 kr. in revenue excl. VAT and 7,237.50 kr. outstanding incl. VAT. The top-customer list is empty on the demo agreement, because its invoices are from 2022. That is also a test: a number that is 0 must have an explanation.

Step 3: Connect the dashboard

Data Studio and Metabase can both read PostgreSQL directly. Create a read-only user and give that to the dashboard. Save the queries above as views (CREATE VIEW) so the tool only sees finished numbers.

What we tripped over ourselves

  • Test on the real database. We once had 320 tests passing on SQLite while four tables were dead in production on MySQL. Run your tests on the same database as production.
  • Reconcile with the source. Our first e-conomic report was wrong although every test was green. Mocks hid the bug, and only a test against real demo data found it.
  • Dinero needs Pro. A free Dinero organisation gets 403 with code 90 from the API.
  • Shopify has two kinds of data. Catalogue data can be read publicly: we have read a Danish jewellery brand’s public Shopify catalogue feed (products.json) to compare prices and price history. Orders and customers, on the other hand, need Shopify’s Admin API and an app with access to the store.
  • One contract instead of many connectors. With many systems, define one small shared API contract of 8–10 endpoints and let every system speak it. We run that pattern in production.

Running the database itself – backups, upgrades and permissions – is covered on database.best-choice.dk.

Sources

  • e-conomic REST API — tokens, demo agreement, page size up to 1,000, checked and tested 19.11.2026

Last reviewed: 2026-12-03

Questions about data flow

Can Data Studio read straight from e-conomic?

Not with a built-in Google connector. Third-party connectors exist, but a database in between gives you history and makes you independent of the connector.

Why PostgreSQL and not a spreadsheet?

A spreadsheet is fine as the end product. As a staging area it lacks primary keys, history and permissions, and it gets slow once you have thousands of rows.

How often should the script run?

Once a day is enough for most KPIs. Fetch only what has changed once the data grows.

What about WooCommerce and the CRM?

Same pattern: one script per source, writing to its own table with a primary key from the source. The dashboard joins the tables on customer number, CVR or e-mail.

Fixed price, no commitment

Get a fixed price for your data task

Tell us briefly what you use today and what you want to achieve. A person answers by e-mail with a proposal and a fixed price before any work starts.

  • A fixed price before we start
  • An answer by e-mail, no calls
  • Your details are used only to answer you

Fields marked with * are required.

What is it about?