As by default megento issue, So we can not make changes in core file, So for this I have make one alternative solution...
I have created one custom invoice interface in my custom module with same API end point : {{magento_api_url}}/V1/invoices/ in webapi.xml file and defined the our custom model with preference in di.xml file and update the invoice state successfully.
Below are the code snippet
Custom Interface
interface InvoiceCustomInterface
{
/**
* save api
* @param \Magento\Sales\Api\Data\InvoiceInterface $entity Invoice interface
* @return \Magento\Sales\Api\Data\InvoiceInterface Invoice interface
*/
public function save($entity);
}
Webapi.xml
<route url="/V1/invoices/" method="POST">
<service class="Vendor\Module_Nmae\Api\InvoiceCustomInterface" method="save"/>
<resources>
<resource ref="Vendor_Module_Nmae::Module_Nmae_invoice" />
</resources>
</route>
di.xml
<preference for="Vendor\Module_Nmae\Api\InvoiceCustomInterface" type="Vendor\Module_Nmae\Model\Api\Invoice"/>
Model file
class Invoice implements InvoiceCustomInterface
{
protected $logger;
/**
* @var InvoiceRepositoryInterface
*/
private $invoiceRepository;
public function __construct(
LoggerInterface $logger,
InvoiceRepositoryInterface $invoiceRepository
)
{
$this->invoiceRepository = $invoiceRepository;
$this->logger = $logger;
}
/**
* @inheritdoc
* @param $entity
*/
public function save($entity)
{
try {
$invoiceRepo = $this->invoiceRepository->get($entity->getEntityId());
$invoiceRepo->setState($entity->getState());
$this->invoiceRepository->save($invoiceRepo);
} catch (\Exception $e) {
$this->logger->info($e->getMessage());
}
return $invoiceRepo;
}
}
So this solution will resolved the issue.