PHP · 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.
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.php. Its second account has no name:
check-chart.php
<?php
// check-chart.php - checks a chart before sending it. Nothing is written.
require __DIR__ . '/brizo.php';
$answer = 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) {
echo "Valid: {$answer['body']['accepted']} records would be accepted.\n";
} else {
echo "Not valid:\n";
foreach ($answer['body']['errors'] as $error) {
echo " record {$error['records_index']}: {$error['field']} - {$error['code']}\n";
}
}3Run it
php check-chart.phpCheck
Not valid:
record 1: name - required_field_missingRecord 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.
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.