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

Why was ambassador Sondland involved in Ukraine?

Why do new jet engines cost billions to design?

Switching engine coolant with similar properties oil

When to use Sitecore.Context.Items and why?

How to truncate all lines at a certain length?

Selecting elements of a list based on range

Insets around a clock

Does Global Entry require agreeing to a higher standard of behavior?

TV Pilot or Movie, 80s, misfit team with powers

What is the last point where one can throw away fruits if one has indicated "not bringing any fruit" on the US customs form when flying to the US?

Does a resurrected wizard remember his prepared spells?

What kinds of sanctions would be applied if you wrongly invoked the fifth amendment?

Why is hydro-electric power still scarce in some places?

Does the coriolis force have an effect on the direction in which an aircraft travels?

What should I tell a customer when my co-worker fails to show up to a meeting?

Is there a text editor that can run shell scripts?

Is the genre 'fantasy' still fantasy without magic?

What is an example of a sequence which "thins out" and is finite?

Has Donald Duck ever had any love interest besides Daisy?

Why does Greedo say "Maclunkey" in the Mos Eisley Cantina?

Is there any math conjecture that would cause a lot of damage if disproven?

SMD ceramic capacitor 0805 vs 1206

How can mages regard fast magic as a form of evil?

Does casting Inflict Wounds while concentrating on Vampiric Touch also siphon damage?



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;









3


















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

































    3


















    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





























      3













      3









      3


      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,7181 gold badge13 silver badges29 bronze badges




      1,7181 gold badge13 silver badges29 bronze badges























          2 Answers
          2






          active

          oldest

          votes


















          4



















          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


















          4



















          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/4.0/"u003ecc by-sa 4.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









          4



















          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















          4



















          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













          4















          4











          4









          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,4001 gold badge3 silver badges23 bronze badges




          1,4001 gold badge3 silver badges23 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













          4



















          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















          4



















          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













          4















          4











          4









          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,7671 gold badge9 silver badges40 bronze badges




          4,7671 gold badge9 silver badges40 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

          Tamil (spriik) Luke uk diar | Nawigatjuun

          Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

          Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?