A seller on Wildberries and Ozon has two seller cabinets, each with its own reports, its own definitions and its own limits on history. The Wildberries statistics API keeps orders and sales for 90 days. Stock levels on both marketplaces are only available for the current moment, never for a past date. If you want to see how sales and stock moved over a season, you have to collect the data yourself, every day, without gaps.
We built this for an e-commerce seller. Eleven n8n workflows pull sales, stock and finance data from both marketplace APIs into PostgreSQL, and four Grafana dashboards answer the morning questions. Everything runs on Docker Compose behind Cloudflare Tunnel, with separate stage and production and encrypted offsite backups. This article covers what the seller sees, how the pipelines are built, and what we left out.
What the seller needs every morning
There are four dashboards, in this order:
- Collection status. For each of the 13 data sources: when it last wrote data, how many rows in the last 24 hours, and hours since the last write, yellow after 26 and red after 50. It comes first because every other number is only as good as the data behind it. A pipeline that silently stopped on Tuesday makes Thursday’s sales chart look like a bad week.
- Sales. Orders and buyouts by day on both marketplaces, cancellations, top products, and where orders go: by country on Wildberries, by delivery cluster on Ozon.
- Stock. Units in the seller’s own warehouse and in the marketplace warehouses, per product, with days of cover. Days of cover is the stock in marketplace warehouses divided by average daily orders over the last 30 days. It answers the practical question: which products need a new shipment.
- Finance. From the weekly Wildberries report: payouts for sold goods minus returns, logistics, storage, acceptance, penalties and deductions. From Ozon accruals: commission, logistics and penalties. Also Ozon cash flow by payout period, matching the Finance section of the Ozon cabinet.
One detail on the stock dashboard is worth copying. For goods shipped from the seller’s own warehouse (FBS), the number the marketplace shows is whatever the seller uploaded, and sellers often keep it above what is on the shelf on purpose. So days of cover is computed from marketplace warehouses only, and the panel description says so. A dashboard that mixes the two would give confident, wrong answers.
Raw JSON first, typed views on top
API data goes into PostgreSQL as it comes, in jsonb columns, next to a primary key and the one or two columns needed for incremental loading. A raw schema holds these tables. A mart schema holds views that extract typed columns for the dashboards.
CREATE TABLE IF NOT EXISTS raw.wb_orders (
srid text PRIMARY KEY, -- unique ID of an order line
last_change_date timestamp NOT NULL, -- Moscow time, as the API returns it
data jsonb NOT NULL,
loaded_at timestamptz NOT NULL DEFAULT now()
);
CREATE OR REPLACE VIEW mart.orders AS
SELECT o.srid,
(o.data->>'date')::timestamp AS order_dt,
(o.data->>'nmId')::bigint AS nm_id,
(o.data->>'priceWithDisc')::numeric AS price_with_disc,
(o.data->>'isCancel')::boolean AS is_cancel,
o.data->>'warehouseName' AS warehouse
FROM raw.wb_orders o;
Marketplace APIs add and rename fields. When a new field becomes interesting, it is one more line in a view, and the history already contains it: no reload, no migration of old rows. The views are also the only place that knows the API’s field names.
There are two database roles. n8n writes with one of them. Grafana and ad-hoc queries use the other, which is read-only, so a dashboard mistake cannot change data.
Incremental loads
Each workflow starts by asking the database where it stopped. The rules differ per endpoint, because the data behaves differently:
- Wildberries orders and sales: start from the latest
lastChangeDatealready stored, minus one minute. With an empty table, start 89 days back, because the API keeps 90. Dates in this API are Moscow time, so the query works in Moscow time too. - Wildberries finance report: start from the end of the last loaded report minus three weeks, because recent reports get corrected.
- Ozon orders, FBS and FBO: re-read the last 30 days on every run, because an order’s status keeps changing until delivery or return. The first run loads 364 days, the most the API returns.
- Ozon accruals: every new order plus every order from the last 60 days, because charges keep arriving for weeks after delivery. The order numbers go out in batches of 200.
- Stock: a full snapshot, twice a day.
-- Wildberries orders: where this run starts
SELECT to_char(coalesce(max(last_change_date) - interval '1 minute',
(now() AT TIME ZONE 'Europe/Moscow') - interval '89 days'),
'YYYY-MM-DD"T"HH24:MI:SS') AS "dateFrom"
FROM raw.wb_orders;
The overlapping windows are deliberate. Reading the same rows twice costs a little API time, while missing a row means a wrong report. Overlap is only safe if writes are idempotent, which is the next section.
Idempotent upserts
Every write is INSERT ... ON CONFLICT DO UPDATE on the marketplace’s own unique key: order line ID, sale ID, report row ID or posting number. Run a workflow twice or reload a whole month, and you end up with the same table.
WITH page AS (
SELECT DISTINCT ON (r->>'srid') r
FROM jsonb_array_elements($1::jsonb) AS r
ORDER BY r->>'srid', (r->>'lastChangeDate')::timestamp DESC
)
INSERT INTO raw.wb_orders (srid, last_change_date, data)
SELECT r->>'srid', (r->>'lastChangeDate')::timestamp, r FROM page
ON CONFLICT (srid) DO UPDATE
SET last_change_date = EXCLUDED.last_change_date, data = EXCLUDED.data, loaded_at = now();
Two details matter here. The whole page goes to PostgreSQL as a single JSON parameter, so each page is one statement instead of thousands of single-row inserts from n8n. And DISTINCT ON keeps only the latest version of each key within the page. Without it, a key that appears twice in one page makes PostgreSQL reject the whole statement with “ON CONFLICT DO UPDATE command cannot affect row a second time”.
Stock works differently. There is no “last change” to continue from, and a product that left a warehouse simply disappears from the response. So a small PL/pgSQL function replaces the day’s snapshot in one transaction: it deletes the day’s rows and inserts the new ones. Before calling it, the workflow checks the shape of the response. An unexpected response raises an error, so it can never replace the day’s stock with an empty list. There are two runs a day, around noon and before midnight. If one fails, the day still gets a snapshot, which matters because stock cannot be fetched for a past date.
Pagination and rate limits in n8n
Every paged workflow is the same loop: state, HTTP request, parse, route, then save and go to the next page, or stop. The HTTP Request node returns the full response and never fails on its own. Instead, a Code node looks at the status code and decides what happens next:
// 200 with rows: save; 429: wait and repeat the same page; empty: done; anything else: error.
const r = $json;
const state = $('State').item.json;
const rows = Array.isArray(r.body) ? r.body : [];
const last = rows.length ? rows[rows.length - 1] : null;
return {
json: {
statusCode: r.statusCode,
count: rows.length,
rows: JSON.stringify(rows),
dateFrom: last ? last.lastChangeDate : state.dateFrom, // cursor for the next page
full: rows.length >= 80000, // a full page means there is more
detail: r.statusCode >= 400 ? JSON.stringify(r.body).slice(0, 500) : '',
},
};
A Switch node routes on that result. Anything unexpected ends in a Stop and Error node, with the status code and the first 500 characters of the response in the message. On top of that, the HTTP node retries network errors three times, five seconds apart.
Each API has its own limits, and the workflows encode the ones that applied when we built them:
- Wildberries statistics: up to 80,000 rows per page and one request per minute, so there is a 61-second Wait between pages and after a 429.
- Wildberries stock report: three requests per minute. The HTTP node’s batching sends one item every 21 seconds.
- Wildberries product cards: cursor pagination, 100 cards per page, with a 2-second pause between pages.
- Ozon: limits requests per second. The HTTP node’s batch interval sends items on a timer without waiting for responses. With a 1-second interval, accrual requests got 429 responses, and with 2 seconds they did not. The finance requests now go out every 2.5 seconds, and a 429 sends the item back through a 5-second wait, up to five times.
Where volumes were small enough to skip pagination, such as the Ozon product list, the parser still checks the totals. If the response is full, the workflow fails with “needs pagination”. A silent cut-off would look exactly like a correct report.
One more setting: successful executions are not saved, because the pages run to megabytes. Failed executions are saved in full, so the data that broke a run is there to look at.
Stage, production and hosting
The workflows are not built by hand in the editor. A Python script generates them from templates, so orders and sales, for example, share one template. The resulting JSON is stored in Git and imported with the n8n CLI. Every workflow has two triggers: a schedule, and an Execute Workflow trigger so that it can be run from the command line. The Grafana dashboards are generated the same way and provisioned from files.
Stage has its own PostgreSQL and n8n in a separate Docker network, so stage workflows cannot reach the production database. Stage workflows never run on a schedule, because they use the same read-only API keys as production and share its rate limits. They run by hand, outside the minutes when production collects data. Grafana on stage reads the production database through the read-only role, so dashboard changes are checked against live data.
The stack is PostgreSQL 18, n8n, Grafana and cloudflared on Docker Compose. n8n and Grafana are behind Cloudflare Access, and the database is not exposed. Both databases and the .env are dumped every night and copied offsite, encrypted. An external check runs every five minutes and sends a Telegram message if the tunnel stops answering or the offsite backup gets old. More in n8n in production and Offsite backups for self-hosted n8n.
What we did not need
- A separate ETL tool, queue or cache. For one seller account, eleven n8n workflows, PostgreSQL and Grafana are the whole stack.
- Real time. Orders are collected hourly, stock twice a day, product cards and finance once each morning. Morning decisions do not need minute-level data, and one request per minute on the statistics API would not allow it anyway.
- A typed table for every API field. Raw
jsonbplus views covers it, and history survives field changes. - Pagination everywhere. Only where volumes need it, with an error when they grow past what a single request returns.
- Schedules on stage. They would only compete with production for the same rate limits.
- Execution data for successful runs. The pages run to megabytes, and a successful run leaves nothing to investigate.
Takeaway
The hard part of marketplace analytics is not the charts. It is collecting data every day, without gaps or duplicates, from APIs with short history and strict limits. Store responses raw, load with overlap, write with upserts, replace snapshots in one transaction, and put a “collection status” dashboard first. Once that holds, the sales and finance dashboards are just SQL.
