JavaScript · Track 3 · Tutorial 3 of 6

Deal with refused records

Find out which lines of a month BrizoConsol refused and why - and send the month again so nothing is missing.

You will needThe month from Send it safely more than once.
By the endCode that reports every refused line with its reason, and the way to put the month right.

1Two kinds of refusal

A whole request can be refused - the wrong currency, a locked month - and then nothing is written and the answer is 422. Or single records can be refused while the rest are stored, and then the answer is still 202, with counts.rejected above zero. This tutorial is about the second kind, which is easy to miss.

2Send a month with a mistake

Create refused.mjs. Its last line names account 6100, which the chart doesn't hold:

refused.mjs

// refused.mjs - sends a month with an account code the chart does not hold.
import { call, companyId, show, written } from './brizo.mjs';

const request = written(await call('POST', `/organisations/${companyId}/trial-balances`, {
    declarations: {
        source_reference: 'my-ledger',
        period: '2026-09',
        value_basis: 'company_base',
        rate_direction: 'document_to_base',
        base_currency: 'SGD',
    },
    records: [
        { 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: '6100', debit: 2000.00, credit: 0 }, // not in the chart
    ],
}, { 'Idempotency-Key': `${companyId}-2026-09-v2` }));

await show('Trial balance', request);

3Run it

node refused.mjs

Check

Trial balance: request 93 - 0 created, 0 updated, 5 unchanged, 1 refused
  Refused record 5 (6100): account_not_found - The code 6100 is not in this organisation's chart; send it through the accounts kind first.

show() sees counts.rejected is 1 and asks …/requests/{id}/results for each record's outcome, so you get the reason.

The good lines are stored; the bad one is refused
A refused line doesn't stop the rest: five lines are stored, one comes back refused.

4Fix it and send again

Because a month is sent whole, September is now stored without the refused line. Correct the code - or add the account to the chart first - and send the whole month again with a new key. Sent with a key that was already used, nothing would be written.

# in month.mjs: const version = 'v3';
node month.mjs

Check

Trial balance: request 94 - 1 created, 0 updated, 5 unchanged, 0 refused
Recalculation: pending

6000 is created, because the refused send had left September without it.

Fix, then send the whole month again with a new key
After a refusal: fix the cause, then send the whole month again - with a new key.

5What each refusal means

account_not_foundThe code isn't in the company's chart. Send the chart first, or correct the code.
invalid_valueA figure isn't allowed - a negative debit or credit, for example. Both are positive figures on their own side.
duplicate_record_identityThe same account appears twice in one month. Add the lines together.
required_field_missingA record has no account_code.

Want more detail? See the documentation