JavaScript · Track 2 · Tutorial 2 of 4

Check a chart before you send it

Ask BrizoConsol whether a chart is well formed before you send it - nothing is written, and every problem comes back with the record it's in.

You will needThe chart script from Send your chart of accounts.
By the endA check you can run on any payload before sending it, and an understanding of what it does and doesn't catch.

1When a check is worth it

Before you point your code at a real company, you can ask BrizoConsol whether a payload is well formed - without writing anything. Add /validate to the address and send the same body.

2Check a chart with a mistake in it

Create check-chart.mjs. Its second account has no name:

check-chart.mjs

// check-chart.mjs - checks a chart before sending it. Nothing is written.
import { call, companyId } from './brizo.mjs';

const answer = await call('POST', `/organisations/${companyId}/accounts/validate`, {
    declarations: { source_reference: 'my-ledger' },
    records: [
        { code: '7000', name: 'Bank charges', type: 'Expense' },
        { code: '7100', type: 'Expense' }, // no name
    ],
});

if (answer.status === 200) {
    console.log(`Valid: ${answer.body.accepted} records would be accepted.`);
} else {
    console.log('Not valid:');
    for (const error of answer.body.errors) {
        console.log(`  record ${error.records_index}: ${error.field} - ${error.code}`);
    }
}
What a check looks at, and what it doesn't
What a check covers: the shape of each record. Whether the type exists is only checked when you send.

3Run it

node check-chart.mjs

Check

Not valid:
  record 1: name - required_field_missing

Record 1 - the second record, counting from 0 - has no name. Add a name and run it again, and it answers Valid: 2 records would be accepted.

The two answers a check can give
Two possible answers: 200 with how many records would be accepted, or 422 with each problem.

4What a check can't tell you

A check looks at each record's shape. It doesn't look up whether the account type exists or whether the company has room for more accounts: those are only known when you send. And it writes nothing - a check is never a substitute for sending.

Want more detail? See the documentation