Is any one having tried to create REST API so using custom API one can trigger re-indexing?
which method do i have to mention in webapi.xml file as this is purely AREA::ADMIN activitiy. currently tried with POST (create) and PUT (Update).
Below is the webapi.xml
<route url="/V1/customapi" method="POST">
<service class="Sark\CustomApi\Api\CustomRepositoryInterface" method="create"/>
<resources>
<resource ref="self"/>
</resources>
</route>
Further, for controller do i have to create API folder and interface mandatory or it is optional.
Index pro-grammatically code is as follows:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$indexerCollectionFactory = $objectManager->get("\Magento\Indexer\Model\Indexer\CollectionFactory");
$indexerFactory = $objectManager->get("\Magento\Indexer\Model\IndexerFactory");
$indexerCollection = $indexerCollectionFactory->create();
$allIds = $indexerCollection->getAllIds();
foreach ($allIds as $id) {
$indexer = $indexerFactory->create()->load($id);
$indexer->reindexAll();
}
It would be good if any other API is also there to do the same magic (except the direct custom script file).
Ref.: http://codetheatres.com/magento/creating-custom-api-in-magento2-using-rest-protocol/