If you see in file magento/module-customer-balance/Model/Balance/History.php
line no: 154. You need to set setBalanceModel
and setHistoryAction
like this
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
// for Update customer balance history set setHistoryAction(2)
$customerBalance = $obj->create(\Magento\CustomerBalance\Model\BalanceFactory::class)->create()->load(2)->setHistoryAction(2);
$customerBalanceHistory = $obj->create(\Magento\CustomerBalance\Model\Balance\History::class)->create()
->setBalanceModel($customerBalance)
->setId(2)
->setAdditionalInfo('test')
->save();
// for new entry use set setHistoryAction(1)
$customerBalance = $obj->create(\Magento\CustomerBalance\Model\BalanceFactory::class)->create()->load(2)->setHistoryAction(1);
$customerBalanceHistory = $obj->create(\Magento\CustomerBalance\Model\Balance\HistoryFactory::class)->create()
->setBalanceModel($customerBalance)
->setAdditionalInfo('test')
->save();
Hope this will solve your problem.