JavaScript · Track 8 · Tutorial 1 of 4
Put the steps in order
Put everything together in one run: the chart, the month, the detail, and the consolidation request - in the order BrizoConsol needs them.
1Put it together
Every track so far sent one thing. A monthly run sends them all, in the order BrizoConsol needs them.
2Write the run
Create monthly.mjs. Its two functions return the same data the earlier tutorials sent: replace them with reads from your own system.
monthly.mjs
// Replace these with reads from your own system. They return the same shapes the earlier tutorials sent.
function chartFromMySystem() {
return [
{ code: '1000', name: 'Operating bank', type: 'Bank' },
{ code: '1200', name: 'Trade receivables', type: 'Accounts Receivable' },
{ code: '2000', name: 'Trade payables', type: 'Accounts Payable' },
{ code: '4000', name: 'Sales revenue', type: 'Revenue' },
{ code: '5000', name: 'Cost of sales', type: 'Direct Costs' },
{ code: '6000', name: 'Rent', type: 'Expense' },
];
}
function trialBalanceFromMySystem(period) {
return [
{ account_code: '1000', debit: 20000.00, credit: 0 },
{ account_code: '1200', debit: 5000.00, credit: 0 },
{ account_code: '2000', debit: 0, credit: 5000.00 },
{ account_code: '4000', debit: 0, credit: 30000.00 },
{ account_code: '5000', debit: 8000.00, credit: 0 },
{ account_code: '6000', debit: 2000.00, credit: 0 },
];
}The run itself:
monthly.mjs
function declarations(source, period, currency, webhook) {
const declarations = {
source_reference: source,
period,
value_basis: 'company_base',
rate_direction: 'document_to_base',
base_currency: currency,
};
if (webhook !== null) {
declarations.webhook_url = webhook;
}
return declarations;
}
console.log(`Sending ${period}`);
// 1. The chart first: a trial balance can only name accounts the chart already holds.
await show('Chart', written(await call('POST', `/organisations/${companyId}/accounts`, {
declarations: { source_reference: 'my-ledger', mode: 'merge' },
records: chartFromMySystem(),
})));
// 2. The month, whole. The key makes a retry of this run harmless.
const month = written(await call('POST', `/organisations/${companyId}/trial-balances`, {
declarations: declarations('my-ledger', period, currency, webhook),
records: trialBalanceFromMySystem(period),
}, { 'Idempotency-Key': `${companyId}-${period}-${version}` }));
await show('Trial balance', month);
// 3. Invoices, bills and journal lines go here, as in tracks 4 and 5.
// 4. Ask for tonight's consolidation, once, after the last write.
const run = written(await call('POST', `/organisations/${companyId}/consolidation-requests`)).data;
console.log(`Consolidation request ${run.id}: ${run.status}`);
// Keep these two numbers: tomorrow, check-run.mjs reads what became of them.
writeFileSync(new URL(`./run-${period}.json`, import.meta.url), JSON.stringify({ month: month.id, consolidation: run.id }));
console.log(`Tomorrow: node check-run.mjs ${month.id} ${run.id}`);
3Run it
node monthly.mjs 2026-09Check
Sending 2026-09
Chart: request 101 - 0 created, 1 updated, 5 unchanged, 0 refused
Trial balance: request 92 - 6 created, 0 updated, 0 unchanged, 0 refused
Consolidation request 12: pending
Tomorrow: node check-run.mjs 92 12The trial balance answers the request from before, because the key is the same: nothing was written twice.
4Run it every month
Schedule it for after your books close each month - with cron, the Windows Task Scheduler, or your own scheduler - and schedule check-run.mjs for the next morning. Without a month on the command line, it sends last month.
Want more detail? See the documentation