REST API - dispatch events












1















I have custom module and my code structure is as per service contact.




app/code/[Vendor]/[Module]/Model/AccountManagement.php




Now i have a dispatch event in my model file



$this->_eventManager->dispatch('vendor_register_success', $eventParams);


As per REST API standard and as per the this solution i added event in specific module where it comes from.




app/code/[Vendor]/[Module]/etc/webapi_rest/events.xml




<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="vendor_register_success">
<observer name="vendor_register_success" instance="[Vendor][Module]ObserverVendorBrandRegister" />
</event>
</config>


and My observer looks like this




app/code/[Vendor]/[Module]/Observer/VendorBrandRegister.php




 public function execute(MagentoFrameworkEventObserver $observer)
{
echo "In execute"; exit;
}


but this event is not dispatching.
What am i missing Because as per the solution i need to add events in webapi_rest folder in etc folder.










share|improve this question



























    1















    I have custom module and my code structure is as per service contact.




    app/code/[Vendor]/[Module]/Model/AccountManagement.php




    Now i have a dispatch event in my model file



    $this->_eventManager->dispatch('vendor_register_success', $eventParams);


    As per REST API standard and as per the this solution i added event in specific module where it comes from.




    app/code/[Vendor]/[Module]/etc/webapi_rest/events.xml




    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="vendor_register_success">
    <observer name="vendor_register_success" instance="[Vendor][Module]ObserverVendorBrandRegister" />
    </event>
    </config>


    and My observer looks like this




    app/code/[Vendor]/[Module]/Observer/VendorBrandRegister.php




     public function execute(MagentoFrameworkEventObserver $observer)
    {
    echo "In execute"; exit;
    }


    but this event is not dispatching.
    What am i missing Because as per the solution i need to add events in webapi_rest folder in etc folder.










    share|improve this question

























      1












      1








      1








      I have custom module and my code structure is as per service contact.




      app/code/[Vendor]/[Module]/Model/AccountManagement.php




      Now i have a dispatch event in my model file



      $this->_eventManager->dispatch('vendor_register_success', $eventParams);


      As per REST API standard and as per the this solution i added event in specific module where it comes from.




      app/code/[Vendor]/[Module]/etc/webapi_rest/events.xml




      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
      <event name="vendor_register_success">
      <observer name="vendor_register_success" instance="[Vendor][Module]ObserverVendorBrandRegister" />
      </event>
      </config>


      and My observer looks like this




      app/code/[Vendor]/[Module]/Observer/VendorBrandRegister.php




       public function execute(MagentoFrameworkEventObserver $observer)
      {
      echo "In execute"; exit;
      }


      but this event is not dispatching.
      What am i missing Because as per the solution i need to add events in webapi_rest folder in etc folder.










      share|improve this question














      I have custom module and my code structure is as per service contact.




      app/code/[Vendor]/[Module]/Model/AccountManagement.php




      Now i have a dispatch event in my model file



      $this->_eventManager->dispatch('vendor_register_success', $eventParams);


      As per REST API standard and as per the this solution i added event in specific module where it comes from.




      app/code/[Vendor]/[Module]/etc/webapi_rest/events.xml




      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
      <event name="vendor_register_success">
      <observer name="vendor_register_success" instance="[Vendor][Module]ObserverVendorBrandRegister" />
      </event>
      </config>


      and My observer looks like this




      app/code/[Vendor]/[Module]/Observer/VendorBrandRegister.php




       public function execute(MagentoFrameworkEventObserver $observer)
      {
      echo "In execute"; exit;
      }


      but this event is not dispatching.
      What am i missing Because as per the solution i need to add events in webapi_rest folder in etc folder.







      magento2 event-observer rest-api






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 22 '18 at 6:46









      Aditya ShahAditya Shah

      3,7022834




      3,7022834






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Try below code for dispatch event.



          $this->_eventManager->dispatch('vendor_register_success', [$eventParams]);


          Instead of



          $this->_eventManager->dispatch('vendor_register_success', $eventParams);


          As second parameter should be an array. This may help you.






          share|improve this answer
























          • Tried this solution. Not working.

            – Aditya Shah
            Jun 22 '18 at 10:03











          • It's specific webapi_rest related issue.. how to dispatch event in that.

            – Aditya Shah
            Jun 22 '18 at 10:04











          • You have done proper, I have seen only difference that I have mentioned. In my opinion First check the code s executed or not?

            – Prasanta Hatui
            Jun 22 '18 at 10:34











          • No, it's not going in execute function, now i am not magento allows or not dispatch event in model for service contact

            – Aditya Shah
            Jun 22 '18 at 10:39






          • 1





            + for your efforts man !! :)

            – Aditya Shah
            Jun 22 '18 at 11:19



















          0














          This can be done by defining events.xml in webapi_rest folder.




          vendor/magento/module-quote/etc/webapi_rest/events.xml




          Magento is doing it in quote module for sending mail.



          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
          <event name="sales_model_service_quote_submit_success">
          <observer name="sendEmail" instance="MagentoQuoteObserverWebapiSubmitObserver" />
          </event>
          </config>


          Reference 1 - From Vinai Kopp: https://twitter.com/VinaiKopp/status/810897855527485440



          Reference 2





          share























            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%2f230953%2frest-api-dispatch-events%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Try below code for dispatch event.



            $this->_eventManager->dispatch('vendor_register_success', [$eventParams]);


            Instead of



            $this->_eventManager->dispatch('vendor_register_success', $eventParams);


            As second parameter should be an array. This may help you.






            share|improve this answer
























            • Tried this solution. Not working.

              – Aditya Shah
              Jun 22 '18 at 10:03











            • It's specific webapi_rest related issue.. how to dispatch event in that.

              – Aditya Shah
              Jun 22 '18 at 10:04











            • You have done proper, I have seen only difference that I have mentioned. In my opinion First check the code s executed or not?

              – Prasanta Hatui
              Jun 22 '18 at 10:34











            • No, it's not going in execute function, now i am not magento allows or not dispatch event in model for service contact

              – Aditya Shah
              Jun 22 '18 at 10:39






            • 1





              + for your efforts man !! :)

              – Aditya Shah
              Jun 22 '18 at 11:19
















            1














            Try below code for dispatch event.



            $this->_eventManager->dispatch('vendor_register_success', [$eventParams]);


            Instead of



            $this->_eventManager->dispatch('vendor_register_success', $eventParams);


            As second parameter should be an array. This may help you.






            share|improve this answer
























            • Tried this solution. Not working.

              – Aditya Shah
              Jun 22 '18 at 10:03











            • It's specific webapi_rest related issue.. how to dispatch event in that.

              – Aditya Shah
              Jun 22 '18 at 10:04











            • You have done proper, I have seen only difference that I have mentioned. In my opinion First check the code s executed or not?

              – Prasanta Hatui
              Jun 22 '18 at 10:34











            • No, it's not going in execute function, now i am not magento allows or not dispatch event in model for service contact

              – Aditya Shah
              Jun 22 '18 at 10:39






            • 1





              + for your efforts man !! :)

              – Aditya Shah
              Jun 22 '18 at 11:19














            1












            1








            1







            Try below code for dispatch event.



            $this->_eventManager->dispatch('vendor_register_success', [$eventParams]);


            Instead of



            $this->_eventManager->dispatch('vendor_register_success', $eventParams);


            As second parameter should be an array. This may help you.






            share|improve this answer













            Try below code for dispatch event.



            $this->_eventManager->dispatch('vendor_register_success', [$eventParams]);


            Instead of



            $this->_eventManager->dispatch('vendor_register_success', $eventParams);


            As second parameter should be an array. This may help you.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 22 '18 at 9:55









            Prasanta HatuiPrasanta Hatui

            1,4121414




            1,4121414













            • Tried this solution. Not working.

              – Aditya Shah
              Jun 22 '18 at 10:03











            • It's specific webapi_rest related issue.. how to dispatch event in that.

              – Aditya Shah
              Jun 22 '18 at 10:04











            • You have done proper, I have seen only difference that I have mentioned. In my opinion First check the code s executed or not?

              – Prasanta Hatui
              Jun 22 '18 at 10:34











            • No, it's not going in execute function, now i am not magento allows or not dispatch event in model for service contact

              – Aditya Shah
              Jun 22 '18 at 10:39






            • 1





              + for your efforts man !! :)

              – Aditya Shah
              Jun 22 '18 at 11:19



















            • Tried this solution. Not working.

              – Aditya Shah
              Jun 22 '18 at 10:03











            • It's specific webapi_rest related issue.. how to dispatch event in that.

              – Aditya Shah
              Jun 22 '18 at 10:04











            • You have done proper, I have seen only difference that I have mentioned. In my opinion First check the code s executed or not?

              – Prasanta Hatui
              Jun 22 '18 at 10:34











            • No, it's not going in execute function, now i am not magento allows or not dispatch event in model for service contact

              – Aditya Shah
              Jun 22 '18 at 10:39






            • 1





              + for your efforts man !! :)

              – Aditya Shah
              Jun 22 '18 at 11:19

















            Tried this solution. Not working.

            – Aditya Shah
            Jun 22 '18 at 10:03





            Tried this solution. Not working.

            – Aditya Shah
            Jun 22 '18 at 10:03













            It's specific webapi_rest related issue.. how to dispatch event in that.

            – Aditya Shah
            Jun 22 '18 at 10:04





            It's specific webapi_rest related issue.. how to dispatch event in that.

            – Aditya Shah
            Jun 22 '18 at 10:04













            You have done proper, I have seen only difference that I have mentioned. In my opinion First check the code s executed or not?

            – Prasanta Hatui
            Jun 22 '18 at 10:34





            You have done proper, I have seen only difference that I have mentioned. In my opinion First check the code s executed or not?

            – Prasanta Hatui
            Jun 22 '18 at 10:34













            No, it's not going in execute function, now i am not magento allows or not dispatch event in model for service contact

            – Aditya Shah
            Jun 22 '18 at 10:39





            No, it's not going in execute function, now i am not magento allows or not dispatch event in model for service contact

            – Aditya Shah
            Jun 22 '18 at 10:39




            1




            1





            + for your efforts man !! :)

            – Aditya Shah
            Jun 22 '18 at 11:19





            + for your efforts man !! :)

            – Aditya Shah
            Jun 22 '18 at 11:19













            0














            This can be done by defining events.xml in webapi_rest folder.




            vendor/magento/module-quote/etc/webapi_rest/events.xml




            Magento is doing it in quote module for sending mail.



            <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
            <event name="sales_model_service_quote_submit_success">
            <observer name="sendEmail" instance="MagentoQuoteObserverWebapiSubmitObserver" />
            </event>
            </config>


            Reference 1 - From Vinai Kopp: https://twitter.com/VinaiKopp/status/810897855527485440



            Reference 2





            share




























              0














              This can be done by defining events.xml in webapi_rest folder.




              vendor/magento/module-quote/etc/webapi_rest/events.xml




              Magento is doing it in quote module for sending mail.



              <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
              <event name="sales_model_service_quote_submit_success">
              <observer name="sendEmail" instance="MagentoQuoteObserverWebapiSubmitObserver" />
              </event>
              </config>


              Reference 1 - From Vinai Kopp: https://twitter.com/VinaiKopp/status/810897855527485440



              Reference 2





              share


























                0












                0








                0







                This can be done by defining events.xml in webapi_rest folder.




                vendor/magento/module-quote/etc/webapi_rest/events.xml




                Magento is doing it in quote module for sending mail.



                <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
                <event name="sales_model_service_quote_submit_success">
                <observer name="sendEmail" instance="MagentoQuoteObserverWebapiSubmitObserver" />
                </event>
                </config>


                Reference 1 - From Vinai Kopp: https://twitter.com/VinaiKopp/status/810897855527485440



                Reference 2





                share













                This can be done by defining events.xml in webapi_rest folder.




                vendor/magento/module-quote/etc/webapi_rest/events.xml




                Magento is doing it in quote module for sending mail.



                <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
                <event name="sales_model_service_quote_submit_success">
                <observer name="sendEmail" instance="MagentoQuoteObserverWebapiSubmitObserver" />
                </event>
                </config>


                Reference 1 - From Vinai Kopp: https://twitter.com/VinaiKopp/status/810897855527485440



                Reference 2






                share











                share


                share










                answered 5 mins ago









                Aditya ShahAditya Shah

                3,7022834




                3,7022834






























                    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%2f230953%2frest-api-dispatch-events%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

                    Magento 2 controller redirect on button click in phtml file

                    Polycentropodidae