How do I create an events observer that only calls when the REST API dispatches events?How to get the name of the triggered event?How to obtain a JSON order rendered by the REST API in the sales_order_place_after event observerMagento2: frontend event is not working (sales_order_place_after)Magento 2.1.1 Rest API Update price onlyM2: Why My Observer Is Not Firing For API CallsMagento 2 - Category Save Event is not called when save category via rest apiHow to get Product via API right after product created?REST API - dispatch eventsEvents when the order is placed is not firing

Circular Reasoning for Epsilon-Delta Proof?

How do I make my image comply with the requirements of this photography competition?

How can I unambiguously ask for a new user's "Display Name"?

Nothing like a good ol' game of ModTen

Compelling story with the world as a villain

How to find out the average duration of the peer-review process for a given journal?

Can I get temporary health insurance while moving to the US?

Papers on arXiv solving the same problem at the same time

Where was Carl Sagan working on a plan to detonate a nuke on the Moon? Where was he applying when he leaked it?

Are the players on the same team as the DM?

Prevent use of CNAME Record for Untrusted Domain

Are modern clipless shoes and pedals that much better than toe clips and straps?

Could George I (of Great Britain) speak English?

How do the Etherealness and Banishment spells interact?

Does an atom recoil when photon radiate?

Can RMSE and MAE have the same value?

How to gently end involvement with an online community?

Numbers Decrease while Letters Increase

What would make bones be of different colors?

Is MOSFET active device?

Network helper class with retry logic on failure

Is "The life is beautiful" incorrect or just very non-idiomatic?

Do they have Supervillain(s)?

Did anyone try to find the little box that held Professor Moriarty and his wife after the crash?



How do I create an events observer that only calls when the REST API dispatches events?


How to get the name of the triggered event?How to obtain a JSON order rendered by the REST API in the sales_order_place_after event observerMagento2: frontend event is not working (sales_order_place_after)Magento 2.1.1 Rest API Update price onlyM2: Why My Observer Is Not Firing For API CallsMagento 2 - Category Save Event is not called when save category via rest apiHow to get Product via API right after product created?REST API - dispatch eventsEvents when the order is placed is not firing






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








2















I just want to call an event observer when the event is dispatched via the REST API. Like if an order is placed from a mobile application, only then the sales_order_save_afterObserver should be called.



How do I write code for the same in events.xml? Or do we have to write somewhere else?










share|improve this question
































    2















    I just want to call an event observer when the event is dispatched via the REST API. Like if an order is placed from a mobile application, only then the sales_order_save_afterObserver should be called.



    How do I write code for the same in events.xml? Or do we have to write somewhere else?










    share|improve this question




























      2












      2








      2


      1






      I just want to call an event observer when the event is dispatched via the REST API. Like if an order is placed from a mobile application, only then the sales_order_save_afterObserver should be called.



      How do I write code for the same in events.xml? Or do we have to write somewhere else?










      share|improve this question
















      I just want to call an event observer when the event is dispatched via the REST API. Like if an order is placed from a mobile application, only then the sales_order_save_afterObserver should be called.



      How do I write code for the same in events.xml? Or do we have to write somewhere else?







      magento2 event-observer rest






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 13 at 4:06









      Peter Mortensen

      2091 silver badge8 bronze badges




      2091 silver badge8 bronze badges










      asked Aug 12 at 10:41









      Navin BhudiyaNavin Bhudiya

      1,0281 gold badge13 silver badges28 bronze badges




      1,0281 gold badge13 silver badges28 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          3















          You have to place a events.xml in the webapi_rest area: app/[Vendor]/[Module]/etc/webapi_rest/events.xml



          By placing the events.xml in the webapi_restdirectory the observer only listens to events dispatched in that area.



          You can read about the areas and events in the devdocs.






          share|improve this answer



























          • How can i print what event currently i am using into log file @Daniel

            – zus
            Aug 14 at 9:18












          • @zus You'll need to inject PsrLogLoggerInterface to write to the log. WIth $observer->getEventName() you can get the current event name.

            – Daniel
            Aug 14 at 10:08











          • For magento 1, how can i do that?

            – zus
            Aug 14 at 10:09











          • here is my code, not working paste.ofcode.org/UuYfuMtnh84raJux5rUF8A

            – zus
            Aug 14 at 10:16











          • Sorry I don't know for Magento 1. You might ask a separate question for this.

            – Daniel
            Aug 14 at 10:35


















          3















          You can declare your observer at the following location to call it via the REST API only.




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







          share|improve this answer



























          • How can i print what event currently i am using into log file @Dinesh

            – zus
            Aug 14 at 9:18













          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%2f285144%2fhow-do-i-create-an-events-observer-that-only-calls-when-the-rest-api-dispatches%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









          3















          You have to place a events.xml in the webapi_rest area: app/[Vendor]/[Module]/etc/webapi_rest/events.xml



          By placing the events.xml in the webapi_restdirectory the observer only listens to events dispatched in that area.



          You can read about the areas and events in the devdocs.






          share|improve this answer



























          • How can i print what event currently i am using into log file @Daniel

            – zus
            Aug 14 at 9:18












          • @zus You'll need to inject PsrLogLoggerInterface to write to the log. WIth $observer->getEventName() you can get the current event name.

            – Daniel
            Aug 14 at 10:08











          • For magento 1, how can i do that?

            – zus
            Aug 14 at 10:09











          • here is my code, not working paste.ofcode.org/UuYfuMtnh84raJux5rUF8A

            – zus
            Aug 14 at 10:16











          • Sorry I don't know for Magento 1. You might ask a separate question for this.

            – Daniel
            Aug 14 at 10:35















          3















          You have to place a events.xml in the webapi_rest area: app/[Vendor]/[Module]/etc/webapi_rest/events.xml



          By placing the events.xml in the webapi_restdirectory the observer only listens to events dispatched in that area.



          You can read about the areas and events in the devdocs.






          share|improve this answer



























          • How can i print what event currently i am using into log file @Daniel

            – zus
            Aug 14 at 9:18












          • @zus You'll need to inject PsrLogLoggerInterface to write to the log. WIth $observer->getEventName() you can get the current event name.

            – Daniel
            Aug 14 at 10:08











          • For magento 1, how can i do that?

            – zus
            Aug 14 at 10:09











          • here is my code, not working paste.ofcode.org/UuYfuMtnh84raJux5rUF8A

            – zus
            Aug 14 at 10:16











          • Sorry I don't know for Magento 1. You might ask a separate question for this.

            – Daniel
            Aug 14 at 10:35













          3














          3










          3









          You have to place a events.xml in the webapi_rest area: app/[Vendor]/[Module]/etc/webapi_rest/events.xml



          By placing the events.xml in the webapi_restdirectory the observer only listens to events dispatched in that area.



          You can read about the areas and events in the devdocs.






          share|improve this answer















          You have to place a events.xml in the webapi_rest area: app/[Vendor]/[Module]/etc/webapi_rest/events.xml



          By placing the events.xml in the webapi_restdirectory the observer only listens to events dispatched in that area.



          You can read about the areas and events in the devdocs.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 12 at 11:34

























          answered Aug 12 at 11:01









          DanielDaniel

          1,0911 gold badge3 silver badges19 bronze badges




          1,0911 gold badge3 silver badges19 bronze badges















          • How can i print what event currently i am using into log file @Daniel

            – zus
            Aug 14 at 9:18












          • @zus You'll need to inject PsrLogLoggerInterface to write to the log. WIth $observer->getEventName() you can get the current event name.

            – Daniel
            Aug 14 at 10:08











          • For magento 1, how can i do that?

            – zus
            Aug 14 at 10:09











          • here is my code, not working paste.ofcode.org/UuYfuMtnh84raJux5rUF8A

            – zus
            Aug 14 at 10:16











          • Sorry I don't know for Magento 1. You might ask a separate question for this.

            – Daniel
            Aug 14 at 10:35

















          • How can i print what event currently i am using into log file @Daniel

            – zus
            Aug 14 at 9:18












          • @zus You'll need to inject PsrLogLoggerInterface to write to the log. WIth $observer->getEventName() you can get the current event name.

            – Daniel
            Aug 14 at 10:08











          • For magento 1, how can i do that?

            – zus
            Aug 14 at 10:09











          • here is my code, not working paste.ofcode.org/UuYfuMtnh84raJux5rUF8A

            – zus
            Aug 14 at 10:16











          • Sorry I don't know for Magento 1. You might ask a separate question for this.

            – Daniel
            Aug 14 at 10:35
















          How can i print what event currently i am using into log file @Daniel

          – zus
          Aug 14 at 9:18






          How can i print what event currently i am using into log file @Daniel

          – zus
          Aug 14 at 9:18














          @zus You'll need to inject PsrLogLoggerInterface to write to the log. WIth $observer->getEventName() you can get the current event name.

          – Daniel
          Aug 14 at 10:08





          @zus You'll need to inject PsrLogLoggerInterface to write to the log. WIth $observer->getEventName() you can get the current event name.

          – Daniel
          Aug 14 at 10:08













          For magento 1, how can i do that?

          – zus
          Aug 14 at 10:09





          For magento 1, how can i do that?

          – zus
          Aug 14 at 10:09













          here is my code, not working paste.ofcode.org/UuYfuMtnh84raJux5rUF8A

          – zus
          Aug 14 at 10:16





          here is my code, not working paste.ofcode.org/UuYfuMtnh84raJux5rUF8A

          – zus
          Aug 14 at 10:16













          Sorry I don't know for Magento 1. You might ask a separate question for this.

          – Daniel
          Aug 14 at 10:35





          Sorry I don't know for Magento 1. You might ask a separate question for this.

          – Daniel
          Aug 14 at 10:35













          3















          You can declare your observer at the following location to call it via the REST API only.




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







          share|improve this answer



























          • How can i print what event currently i am using into log file @Dinesh

            – zus
            Aug 14 at 9:18















          3















          You can declare your observer at the following location to call it via the REST API only.




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







          share|improve this answer



























          • How can i print what event currently i am using into log file @Dinesh

            – zus
            Aug 14 at 9:18













          3














          3










          3









          You can declare your observer at the following location to call it via the REST API only.




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







          share|improve this answer















          You can declare your observer at the following location to call it via the REST API only.




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








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 13 at 4:06









          Peter Mortensen

          2091 silver badge8 bronze badges




          2091 silver badge8 bronze badges










          answered Aug 12 at 10:59









          Dinesh YadavDinesh Yadav

          4,4241 gold badge9 silver badges38 bronze badges




          4,4241 gold badge9 silver badges38 bronze badges















          • How can i print what event currently i am using into log file @Dinesh

            – zus
            Aug 14 at 9:18

















          • How can i print what event currently i am using into log file @Dinesh

            – zus
            Aug 14 at 9:18
















          How can i print what event currently i am using into log file @Dinesh

          – zus
          Aug 14 at 9:18





          How can i print what event currently i am using into log file @Dinesh

          – zus
          Aug 14 at 9:18

















          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%2f285144%2fhow-do-i-create-an-events-observer-that-only-calls-when-the-rest-api-dispatches%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