Skip to content

Magento 2 – detect orders that are placed via REST API

Is there a way to detect orders that are placed via API? I want to add to those orders a different order number prefix.

I have already created an observer that is changing the prefix based on payment method of the order and I want to extend it to change the prefix based on order placed on web or API.

Event for observer now is sales_order_place_after

I have an observer that is doing that and I want to fix it in observer but what I need to take into consideration are the prefix for:

  • web orders paid by card
  • web orders with bank transfer
  • API orders paid by card
  • API orders with bank transfer

Basically I need 4 types of prefix.

Because of this, the functionality that I need now is a way to detect when an order comes from API vs orders that comes from web

Can someone please help me?