TypeScript Client
@engeene/client is the recommended way to read Engeene data from your own code. You describe the
question; it builds the query, runs it, and hands back something you can render.
import { engeene } from "@engeene/client";
const e = engeene({ baseUrl: "https://trailspark.eu.engeene.com", model: "travel", token });
const result = await e
.sum("bookings.revenue")
.avg("bookings.nights")
.by("customers.country")
.filterForIds("bookings.channel", "web", "app")
.top(10)
.query();
result.toTable(); // for a table
result.toSeries(); // for a charting library
result.toObjects(); // plain objects
It has no dependencies and runs in a browser and in Node. You filter with the values you loaded, read numbers in the units you see in the app, and get groups labelled by name. Write a request body for the query endpoint yourself only for a shape the fluent API does not express.
Install
npm install @engeene/client
The npm package is not published yet. Until it is, ask us for the bundle.
On a static page with no build step, host the bundle yourself (engeene-client.js, one file) and
use the Engeene global. engeene-client.mjs is the same bundle as an ES module.
<script src="/assets/engeene-client.js"></script>
<script>
const e = Engeene.engeene({ baseUrl: "https://trailspark.eu.engeene.com", model: "travel", token });
</script>
Connecting
const e = engeene({
baseUrl: "https://trailspark.eu.engeene.com",
model: "travel",
token, // omit on a page served from the same origin
timezone: "Europe/Prague", // defaults to the viewer's zone
});
tokenmay be a function, called before every request, so a refreshed token needs no new client. On a same-origin page the session cookie is used automatically. API tokens are created under Users → Tokens.baseUrlmust usehttps:. Plainhttp:is accepted only forlocalhost;allowInsecureBaseUrl: trueoverrides this on a network you control.- One client can serve many signed-in users: the schema and value names it remembers are kept per
token, so nobody sees names their role hides. If your token function hands out fresh tokens for
the same user, pass
cacheIdentity: () => session.userIdso the client keeps what it already fetched. Give two users the same identity only if they see exactly the same data.
Asking a question
Measures
sum · avg · min · max · median · percentile(property, rank) · count ·
variance · stddev · sampleVariance · sampleStddev · range · ratio ·
coefficientOfVariation
await e.sum("bookings.revenue").count("bookings.customerId").as("Customers").query();
count(property)always counts distinct values. For a number of rows, count the dataset's id property — every row has a different id. Every result also carriesmatchingRows, the number of rows your filters kept..as("…")names the measure before it. Without it the label comes from your model, e.g."Sum of Revenue".- Properties are always written
dataset.property. Measures and groupings may come from different datasets — Engeene follows the links in your model.
Grouping
e.sum("bookings.revenue")
.by("customers.country", "bookings.channel")
.byTime("bookings.bookedAt", "MONTH")
.byBuckets("bookings.revenue", 100) // histogram, 100-wide ranges
.byBucketBounds("bookings.nights", [3, 7]) // bands: ≤3, 3–7, >7
Bucket sizes and cut points are rounded to the property's decimal places; list cut points in
increasing order. A row with no value falls into one extra group labelled Unknown.
| Time groupings | Label | Use for |
|---|---|---|
YEAR QUARTER MONTH WEEK DAY HOUR |
Mar 2024 |
a trend line |
QUARTER_OF_YEAR MONTH_OF_YEAR WEEK_OF_YEAR DAY_OF_WEEK HOUR_OF_DAY |
Mar |
seasonality |
Filtering
e.sum("bookings.revenue")
.filterForIds("bookings.status", "paid", "shipped")
.excludeIds("bookings.channel", "test")
.filterRange("bookings.revenue", 100, 5000)
.filterBetween("bookings.bookedAt", "2024-01-01", new Date())
.filterLastDays("bookings.bookedAt", 30)
Values are the ones you loaded; a value that does not exist matches nothing. Range bounds are in
the units you see, applied exactly as written (1.005 stays 1.005). Pass null to leave one side
open — filterRange("bookings.revenue", 100, null) is "100 or more". A bound that is not a number
throws EngeeneQueryError (code "invalid-measure-bound") before anything is sent.
A filter can also apply to one measure only, so one result carries a total beside a slice of it:
await e
.sum("bookings.revenue").as("All revenue")
.sum("bookings.revenue").as("Paid revenue").metricForIds("bookings.status", "paid")
.by("customers.country")
.query();
Every query-level filter has a per-measure twin: metricForIds, metricExcludeIds, metricRange,
metricBetween, metricLastDays, and metricWhere(condition) for any other
condition.
Computed measures
A measure can be computed from the others — a rate, a share, a margin. $0 is the first measure you
added, $1 the second:
await e
.sum("bookings.revenue")
.count("bookings.bookingId")
.computed("$0 / $1", "Revenue per booking")
.by("customers.country")
.top(10, { metric: 2 })
.query();
Write 100.0 rather than 100 when you want decimals in the answer. Dividing by zero gives an
empty value, not an error. See Computed Measures.
Top N and ordering
e.sum("bookings.revenue").by("customers.country").top(10)
This orders by the first measure, keeps ten groups and adds an (Other) row with the exact
total of the rest.
top(10, { includeOther: false })drops the(Other)row;bottom(10)is the mirror.top(10, { metric: "count(bookings.customerId)" })ranks by another measure — by its key, its.as(…)label or its position.firstByValue(10, "customers.country")keeps the first ten countries A→Z instead (pass{ direction: "desc" }to reverse);orderByValue("customers.country")sorts every group without trimming. The property must be one of the query's.by(...)properties.
Several questions at once
queryAll sends a dashboard's worth of questions in one request:
const [byCountry, byChannel, total] = await e.queryAll([
e.sum("bookings.revenue").by("customers.country"),
e.sum("bookings.revenue").by("bookings.channel"),
e.sum("bookings.revenue"),
]);
if (byCountry.status === "fulfilled") drawTable(byCountry.value.toTable());
else showError(byCountry.reason);
You get one entry per question, in order, shaped like Promise.allSettled: a question Engeene
refuses comes back as its own rejected entry and never costs you the others.
Builders are immutable, so a partly built query is safe to keep and branch from:
const revenue = e.sum("bookings.revenue").filterLastDays("bookings.bookedAt", 30);
const [top, byChannel] = await e.queryAll([
revenue.by("customers.country").top(10),
revenue.by("bookings.channel"),
]);
Every parent, including the ones with nothing
An ordinary query starts from the rows that hold the numbers, so a company with no bookings never
appears. .reverse(parent) starts from the parent instead — every parent appears, and one with
nothing linked shows a count of 0 and no value for the other measures:
await e
.sum("bookings.total")
.count("bookings.bookingId")
.by("companies.industry")
.reverse("companies")
.query();
Group by properties of the parent. Filters apply to the parent; to narrow the linked rows, use the
per-measure filters. Such a query cannot rank, trim or group by time, so top, bottom, orderBy,
orderByValue, firstByValue, limit and byTime are refused before anything is sent. See
Parent rows with child aggregates.
Reading the answer
result.totals // one number per metric, over the whole filtered scope
result.value() // the single number, for a one-metric query with no grouping
result.rows // { key, labels, values, isOther } per group
result.matchingRows // rows the filters matched
result.metricColumns[0].decimals // decimals to show this metric with
const { columns, rows } = result.toTable(); // arrays of primitives
const { categories, series } = result.toSeries(); // for any charting library
const objects = result.toObjects(); // [{ Country: "Czechia", "Sum of Revenue": 1250.5 }]
const csv = result.toCsv(); // a download
- A measure value of
nullmeans no row contributed a value. Show it as a dash, not0. - Show every value of one measure with
metricColumns[i].decimalsdecimals. - A group your role is not allowed to see reads
Anonymized #42orProtected #42. toCsv()is safe to open in a spreadsheet: a label starting with=,+,-,@, a tab or a carriage return gets a leading', so it shows as text instead of running as a formula.
Listing rows
const rows = await e
.select("bookings.bookingId", "customers.country", "bookings.revenue")
.filterForIds("bookings.status", "paid")
.sortBy("bookings.revenue", "desc")
.limit(50)
.rows();
rows.toTable(); // strings, formatted the way Engeene formats them
rows.toValues(); // numbers as numbers, empty cells as null
Columns may span datasets; a row with no linked record gets an empty cell, never disappears.
- With
.limit(n)you get one window of rows (.offset(n)for the next). - Without a limit,
rows()reads every matching row, page by page (.pageSize(n)changes the page size). A sorted list needs.limit(n). - Reading every row stops at what your token may read in one list — past that you get status
413, never a result that quietly stops short. Narrow it with filters. - If data is loaded into the model while the pages are read,
rows()throwsEngeeneListChangedError(code"list-changed") rather than mix two versions. Run it again, or use.limit(n)when the rows must come from one moment.
Discovering the schema
const catalog = await e.catalog();
catalog.datasetNames(); // ["bookings", "customers", …]
catalog.columnNames(); // ["bookings.revenue", "customers.country", …]
catalog.find("bookings.revenue") // { kind: "measure", displayName: "Revenue", … }
Fetched once per signed-in user. Call e.invalidate() after a model change.
Loading data
await e.upload("website", "web_events_daily", "events_2026-09-21.csv", bytes); // Uint8Array or Blob
await e.triggerIngest("website"); // loads every staged file
upload(model, dataset, filename, body)stages one CSV file. Nothing is loaded yet.triggerIngest(model)loads every staged file of the model in the background and answers straight away. Rows are added or updated on each dataset's Id. Pass{ mode: "replace" }only when the files are a complete copy — it replaces the rows of every dataset that has a new file.
Only one load runs at a time: a second triggerIngest fails with status 409. When the answer
says queued: true, the load starts on its own and there is nothing to retry. The token needs
permission to upload data and to ingest on that model. How files map to columns is in
Loading Best Practices.
Errors
Every failure throws EngeeneError with status, code and requestId (quote it in a support
request). On status 429 or 503, retryAfterSeconds says how long to wait; the client never
retries by itself.
- A mistake caught before anything is sent — an unknown property, a bad bound, an empty or
..name — throwsEngeeneQueryErrorwith a message naming what does exist. - A list whose data changed while it was read throws
EngeeneListChangedError. - Both extend
EngeeneError, so onecatchhandles everything. Test for an unknown property withisUnknownColumnError(error)rather than with the code.
Drawing a visualization or a dashboard in your page
The client can also hand you the finished picture — drawn by your workspace exactly as the app draws it, without menus or controls — and put it in your page:
// A whole saved dashboard, by its id or by the address the app shows for it.
await e.dashboard("https://trailspark.eu.engeene.com/dashboards/d_7f3k2")
.filterForIds("bookings.channel", "Web", "App")
.filterLastDays("bookings.bookedAt", 30)
.renderInto(document.getElementById("dashboard"), { height: "1200px" });
// One visualization, as a dashboard stores it.
await e.visualization({
type: "Chart", chartType: "Cartesian", title: "Revenue by channel",
metrics: [{ property: "bookings.total", aggregation: "Sum" }],
segments: ["bookings.channel"],
})
.filterRange("bookings.total", 10, null)
.renderInto(document.getElementById("chart"));
- Filters are added exactly as on a question —
filterForIds,excludeIds,filterRange,filterBetween,filterLastDays— for a dashboard and a visualization alike, plustimezone(...). On a dashboard, a filter on a property the dashboard already filters replaces that filter, as choosing a value in its filter bar does. - The dashboard looks as it looks to the person whose token you use — their access and restrictions apply — with its own rows, columns, titles and section headings.
renderIntoputs the picture in a frame inside the element (give it aheight); nothing in the picture runs in your page.renderHtml()answers the same page as text, for a server or an email, andrenderText()a drawing for a terminal.- You do not need to write the visualization yourself: turn on Developer Features and use Copy Code on a chart.
- Use your workspace address as
baseUrl— the workspace draws the picture.
Related
- Embedding — show dashboards on your own site
- Query Endpoint and List Endpoint — the HTTP surface underneath
- Models Endpoint — schema discovery