= 400) {
echo sprintf(‘API error: %s’, $response) . PHP_EOL;
$response = false;
}
curl_close($ch);
return $response !== false ? json_decode($response, true) : null;
}
}
// Setting unlimited time limit (updating lots of clients can take a long time).
set_time_limit(0);
if (php_sapi_name() !== ‘cli’) {
echo ‘
';
}// Get collection of all Clients.
$clients = UcrmApiAccess::doRequest('clients') ?: [];
echo sprintf('Found %d clients.', count($clients)) . PHP_EOL;// Go through all Clients and update them.
// In this case we are updating all invoice options to use system defaults.
foreach ($clients as $client) {
$response = UcrmApiAccess::doRequest(
sprintf('clients/%d', $client['id']),
'PATCH',[
'sendInvoiceByPost' => null,
'invoiceMaturityDays' => null,
'stopServiceDue' => null,
'stopServiceDueDays' => null,
]);if ($response !== null) {
echo sprintf('Client ID %d successfully updated.', $client['id']) . PHP_EOL;
} else {
echo sprintf('There was an error in updating client ID %d.', $client['id']) . PHP_EOL;
}
}echo 'Done.' . PHP_EOL;