Magento 2: Run reindexer using REST API Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?No response from POST to custom REST Api routeCreate Custom Rest Api in Magento2 and solution for “InvalidArgumentException” errorMagento 2 Custom Web Api callMagento 2: Run reindexer programmaticallyMagento 1.9 - Create order using REST APIMagento 2 - Best approach for retrieving product data - REST API or Custom Endpoint?Magento 2.2.2 REST API - I need to change the customer password using REST APIMagento 2 Rest API using basic AuthMagento2 currency switcher using rest APIMagento2 REST API get all customers details

Help Recreating a Table

Can this water damage be explained by lack of gutters and grading issues?

Who can become a wight?

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

What were wait-states, and why was it only an issue for PCs?

Does using the Inspiration rules for character defects encourage My Guy Syndrome?

What's the connection between Mr. Nancy and fried chicken?

How to ask rejected full-time candidates to apply to teach individual courses?

Is my guitar’s action too high?

Why isn't everyone flabbergasted about Bran's "gift"?

Why aren't these two solutions equivalent? Combinatorics problem

Why do C and C++ allow the expression (int) + 4*5?

What kind of equipment or other technology is necessary to photograph sprites (atmospheric phenomenon)

Where is Bhagavad Gita referred to as Hari Gita?

Can the van der Waals coefficients be negative in the van der Waals equation for real gases?

What's the difference between using dependency injection with a container and using a service locator?

Trying to enter the Fox's den

What is the evidence that custom checks in Northern Ireland are going to result in violence?

Compiling and throwing simple dynamic exceptions at runtime for JVM

Why these surprising proportionalities of integrals involving odd zeta values?

"Destructive force" carried by a B-52?

What is the ongoing value of the Kanban board to the developers as opposed to management

Does the Pact of the Blade warlock feature allow me to customize the properties of the pact weapon I create?

How can I introduce the names of fantasy creatures to the reader?



Magento 2: Run reindexer using REST API



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?No response from POST to custom REST Api routeCreate Custom Rest Api in Magento2 and solution for “InvalidArgumentException” errorMagento 2 Custom Web Api callMagento 2: Run reindexer programmaticallyMagento 1.9 - Create order using REST APIMagento 2 - Best approach for retrieving product data - REST API or Custom Endpoint?Magento 2.2.2 REST API - I need to change the customer password using REST APIMagento 2 Rest API using basic AuthMagento2 currency switcher using rest APIMagento2 REST API get all customers details



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















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="SarkCustomApiApiCustomRepositoryInterface" 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 = MagentoFrameworkAppObjectManager::getInstance();
$indexerCollectionFactory = $objectManager->get("MagentoIndexerModelIndexerCollectionFactory");
$indexerFactory = $objectManager->get("MagentoIndexerModelIndexerFactory");

$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/










share|improve this question




























    3















    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="SarkCustomApiApiCustomRepositoryInterface" 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 = MagentoFrameworkAppObjectManager::getInstance();
    $indexerCollectionFactory = $objectManager->get("MagentoIndexerModelIndexerCollectionFactory");
    $indexerFactory = $objectManager->get("MagentoIndexerModelIndexerFactory");

    $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/










    share|improve this question
























      3












      3








      3








      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="SarkCustomApiApiCustomRepositoryInterface" 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 = MagentoFrameworkAppObjectManager::getInstance();
      $indexerCollectionFactory = $objectManager->get("MagentoIndexerModelIndexerCollectionFactory");
      $indexerFactory = $objectManager->get("MagentoIndexerModelIndexerFactory");

      $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/










      share|improve this question














      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="SarkCustomApiApiCustomRepositoryInterface" 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 = MagentoFrameworkAppObjectManager::getInstance();
      $indexerCollectionFactory = $objectManager->get("MagentoIndexerModelIndexerCollectionFactory");
      $indexerFactory = $objectManager->get("MagentoIndexerModelIndexerFactory");

      $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/







      api rest-api reindex






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      MageSoftechMageSoftech

      14811




      14811




















          1 Answer
          1






          active

          oldest

          votes


















          1














          Using API indexing is not a good Idea.



          As Indexing run on the command line and it takes much usage on memory & time, So it, not a good idea.



          If you want then change the indexing status of each indexing to pending state and Magento cron automatically do indexing as it was in pending. That is the best Solution.



          Create di.xml at app/code/Sark/CustomApi/etc/ and where you will define a model class CustomRepository at app/code/Sark/CustomApi/Model/ which overrides SarkCustomApiApiCustomRepositoryInterface.



          <?xml version="1.0" ?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="SarkCustomApiApiCustomRepositoryInterface" type="SarkCustomApiModelCustomRepository"/>
          </config>


          And CustomRepository.php code is



          <?php

          namespace SarkCustomApiModel;

          class CustomRepository implements SarkCustomApiApiCustomRepositoryInterface

          /**
          * @var MagentoFrameworkIndexerIndexerRegistry
          */
          private $indexerRegistry;
          /**
          * @var MagentoIndexerModelResourceModelIndexerStateCollectionFactory
          */
          private $stateCollectionFactory;

          public function __construct(
          MagentoFrameworkIndexerIndexerRegistry $indexerRegistry,
          MagentoIndexerModelResourceModelIndexerStateCollectionFactory $stateCollectionFactory
          )
          $this->indexerRegistry = $indexerRegistry;
          $this->stateCollectionFactory = $stateCollectionFactory;


          public function create()

          $indexerStates = $this->stateCollectionFactory->create();
          foreach ($indexerStates->getItems() as $indexerState)
          $indexerState->getIndexerId();
          $indexer = $this->indexerRegistry->get($indexerState->getIndexerId());
          if ($indexer->getId() && !$indexer->isWorking())
          $indexer->setScheduled(true);









          share|improve this answer

























          • Accepted! many thanks for the answer. yes i agreed it will use much resources at server end and it should run on CLI. this will help a lot.

            – MageSoftech
            yesterday











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270845%2fmagento-2-run-reindexer-using-rest-api%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Using API indexing is not a good Idea.



          As Indexing run on the command line and it takes much usage on memory & time, So it, not a good idea.



          If you want then change the indexing status of each indexing to pending state and Magento cron automatically do indexing as it was in pending. That is the best Solution.



          Create di.xml at app/code/Sark/CustomApi/etc/ and where you will define a model class CustomRepository at app/code/Sark/CustomApi/Model/ which overrides SarkCustomApiApiCustomRepositoryInterface.



          <?xml version="1.0" ?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="SarkCustomApiApiCustomRepositoryInterface" type="SarkCustomApiModelCustomRepository"/>
          </config>


          And CustomRepository.php code is



          <?php

          namespace SarkCustomApiModel;

          class CustomRepository implements SarkCustomApiApiCustomRepositoryInterface

          /**
          * @var MagentoFrameworkIndexerIndexerRegistry
          */
          private $indexerRegistry;
          /**
          * @var MagentoIndexerModelResourceModelIndexerStateCollectionFactory
          */
          private $stateCollectionFactory;

          public function __construct(
          MagentoFrameworkIndexerIndexerRegistry $indexerRegistry,
          MagentoIndexerModelResourceModelIndexerStateCollectionFactory $stateCollectionFactory
          )
          $this->indexerRegistry = $indexerRegistry;
          $this->stateCollectionFactory = $stateCollectionFactory;


          public function create()

          $indexerStates = $this->stateCollectionFactory->create();
          foreach ($indexerStates->getItems() as $indexerState)
          $indexerState->getIndexerId();
          $indexer = $this->indexerRegistry->get($indexerState->getIndexerId());
          if ($indexer->getId() && !$indexer->isWorking())
          $indexer->setScheduled(true);









          share|improve this answer

























          • Accepted! many thanks for the answer. yes i agreed it will use much resources at server end and it should run on CLI. this will help a lot.

            – MageSoftech
            yesterday















          1














          Using API indexing is not a good Idea.



          As Indexing run on the command line and it takes much usage on memory & time, So it, not a good idea.



          If you want then change the indexing status of each indexing to pending state and Magento cron automatically do indexing as it was in pending. That is the best Solution.



          Create di.xml at app/code/Sark/CustomApi/etc/ and where you will define a model class CustomRepository at app/code/Sark/CustomApi/Model/ which overrides SarkCustomApiApiCustomRepositoryInterface.



          <?xml version="1.0" ?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="SarkCustomApiApiCustomRepositoryInterface" type="SarkCustomApiModelCustomRepository"/>
          </config>


          And CustomRepository.php code is



          <?php

          namespace SarkCustomApiModel;

          class CustomRepository implements SarkCustomApiApiCustomRepositoryInterface

          /**
          * @var MagentoFrameworkIndexerIndexerRegistry
          */
          private $indexerRegistry;
          /**
          * @var MagentoIndexerModelResourceModelIndexerStateCollectionFactory
          */
          private $stateCollectionFactory;

          public function __construct(
          MagentoFrameworkIndexerIndexerRegistry $indexerRegistry,
          MagentoIndexerModelResourceModelIndexerStateCollectionFactory $stateCollectionFactory
          )
          $this->indexerRegistry = $indexerRegistry;
          $this->stateCollectionFactory = $stateCollectionFactory;


          public function create()

          $indexerStates = $this->stateCollectionFactory->create();
          foreach ($indexerStates->getItems() as $indexerState)
          $indexerState->getIndexerId();
          $indexer = $this->indexerRegistry->get($indexerState->getIndexerId());
          if ($indexer->getId() && !$indexer->isWorking())
          $indexer->setScheduled(true);









          share|improve this answer

























          • Accepted! many thanks for the answer. yes i agreed it will use much resources at server end and it should run on CLI. this will help a lot.

            – MageSoftech
            yesterday













          1












          1








          1







          Using API indexing is not a good Idea.



          As Indexing run on the command line and it takes much usage on memory & time, So it, not a good idea.



          If you want then change the indexing status of each indexing to pending state and Magento cron automatically do indexing as it was in pending. That is the best Solution.



          Create di.xml at app/code/Sark/CustomApi/etc/ and where you will define a model class CustomRepository at app/code/Sark/CustomApi/Model/ which overrides SarkCustomApiApiCustomRepositoryInterface.



          <?xml version="1.0" ?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="SarkCustomApiApiCustomRepositoryInterface" type="SarkCustomApiModelCustomRepository"/>
          </config>


          And CustomRepository.php code is



          <?php

          namespace SarkCustomApiModel;

          class CustomRepository implements SarkCustomApiApiCustomRepositoryInterface

          /**
          * @var MagentoFrameworkIndexerIndexerRegistry
          */
          private $indexerRegistry;
          /**
          * @var MagentoIndexerModelResourceModelIndexerStateCollectionFactory
          */
          private $stateCollectionFactory;

          public function __construct(
          MagentoFrameworkIndexerIndexerRegistry $indexerRegistry,
          MagentoIndexerModelResourceModelIndexerStateCollectionFactory $stateCollectionFactory
          )
          $this->indexerRegistry = $indexerRegistry;
          $this->stateCollectionFactory = $stateCollectionFactory;


          public function create()

          $indexerStates = $this->stateCollectionFactory->create();
          foreach ($indexerStates->getItems() as $indexerState)
          $indexerState->getIndexerId();
          $indexer = $this->indexerRegistry->get($indexerState->getIndexerId());
          if ($indexer->getId() && !$indexer->isWorking())
          $indexer->setScheduled(true);









          share|improve this answer















          Using API indexing is not a good Idea.



          As Indexing run on the command line and it takes much usage on memory & time, So it, not a good idea.



          If you want then change the indexing status of each indexing to pending state and Magento cron automatically do indexing as it was in pending. That is the best Solution.



          Create di.xml at app/code/Sark/CustomApi/etc/ and where you will define a model class CustomRepository at app/code/Sark/CustomApi/Model/ which overrides SarkCustomApiApiCustomRepositoryInterface.



          <?xml version="1.0" ?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
          <preference for="SarkCustomApiApiCustomRepositoryInterface" type="SarkCustomApiModelCustomRepository"/>
          </config>


          And CustomRepository.php code is



          <?php

          namespace SarkCustomApiModel;

          class CustomRepository implements SarkCustomApiApiCustomRepositoryInterface

          /**
          * @var MagentoFrameworkIndexerIndexerRegistry
          */
          private $indexerRegistry;
          /**
          * @var MagentoIndexerModelResourceModelIndexerStateCollectionFactory
          */
          private $stateCollectionFactory;

          public function __construct(
          MagentoFrameworkIndexerIndexerRegistry $indexerRegistry,
          MagentoIndexerModelResourceModelIndexerStateCollectionFactory $stateCollectionFactory
          )
          $this->indexerRegistry = $indexerRegistry;
          $this->stateCollectionFactory = $stateCollectionFactory;


          public function create()

          $indexerStates = $this->stateCollectionFactory->create();
          foreach ($indexerStates->getItems() as $indexerState)
          $indexerState->getIndexerId();
          $indexer = $this->indexerRegistry->get($indexerState->getIndexerId());
          if ($indexer->getId() && !$indexer->isWorking())
          $indexer->setScheduled(true);










          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered 2 days ago









          Amit BeraAmit Bera

          60.2k1678178




          60.2k1678178












          • Accepted! many thanks for the answer. yes i agreed it will use much resources at server end and it should run on CLI. this will help a lot.

            – MageSoftech
            yesterday

















          • Accepted! many thanks for the answer. yes i agreed it will use much resources at server end and it should run on CLI. this will help a lot.

            – MageSoftech
            yesterday
















          Accepted! many thanks for the answer. yes i agreed it will use much resources at server end and it should run on CLI. this will help a lot.

          – MageSoftech
          yesterday





          Accepted! many thanks for the answer. yes i agreed it will use much resources at server end and it should run on CLI. this will help a lot.

          – MageSoftech
          yesterday

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270845%2fmagento-2-run-reindexer-using-rest-api%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form