Guides
Numbers from your contacts
Count and add up the contact list for a dashboard: what it can be measured by, one figure over time, and grouped numbers.
The contact list can answer with numbers, never with people: how many joined this quarter, the total of a money field by month, how many in each suburb. Use it for a dashboard on your own server, or a weekly report from n8n.
Everything here needs the account's token with crm:read, on every plan, and Contacts on the account. An app's server key can't use it.
What can be measured
const metrics = await db.metrics();
for (const m of metrics) console.log(m.key, m.label, m.unit); // people, then each number field the owner has named
const [contacts] = await db.datasets();
for (const c of contacts.columns) console.log(c.column_id, c.kind); // measure, dimension or anchorpeople is a count. Every other metric is a number field the owner has named in Contacts, summed by default. A dimension can be grouped by (a choice, yes/no or text field), and an anchor is a date people can be counted by (created_at, or a date field). Sensitive fields never appear.
One figure over time
const joined = await db.series('people', { range: '90d', grain: 'week', compare: 'previous' });
console.log(joined.total, joined.compare?.delta_pct);
for (const p of joined.points) console.log(p.t, p.value);| Option | Means |
|---|---|
range |
A preset: 7d, 30d, 90d, 12m, mtd, qtd, ytd, fytd (1 July), this_month, last_month, this_fy, last_fy. |
from, to |
Or the dates themselves, YYYY-MM-DD, inclusive. With neither, the last 12 months. |
grain |
day, week, month, quarter, year or fy. Left out, one that suits the range. At most 800 points. |
agg |
For a number field: sum (default), avg, min or max. |
compare |
previous adds the window just before, and the change in percent. |
anchor, tz |
The date people are counted by, and the time zone (default Australia/Sydney). |
Every bucket is filled: one nobody landed in is 0 for a count or sum. applied.defaults says what the hub assumed; say it back with the figure.
Grouped numbers
const bySuburb = await db.aggregate({
measures: [{ column: 'people', agg: 'count' }],
dimensions: ['suburb'],
time: { preset: 'ytd' },
limit: 20,
});Measures and dimensions must be names datasets() lists. The answer has rows, columns, and truncated when there were more than limit.
Your other numbers
Figures that aren't contacts (imported tables, Google Analytics, Search Console) live in Knowledge's Your numbers: see Knowledge from a server.