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


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.


<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]\Observer\VendorBrandRegister" />

and My observer looks like this


 public function execute(\Magento\Framework\Event\Observer $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.


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.

  • Tried this solution. Not working. Jun 22 '18 at 10:03
  • It's specific webapi_rest related issue.. how to dispatch event in that. 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? 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 Jun 22 '18 at 10:39
  • 1
    + for your efforts man !! :) Jun 22 '18 at 11:19

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


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="Magento\Quote\Observer\Webapi\SubmitObserver" />

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

Reference 2


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.