cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 - detect orders that are placed via REST API

Magento 2 - detect orders that are placed via REST API

Hello,

 

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

 

Can someone please help me?

3 REPLIES 3

Re: Magento 2 - detect orders that are placed via REST API

Hello @capoan 

 

You can manage it like below:

Magento 2 database contains a table name 'sales_sequence_profile' which has prefix column and every row contains a meta_id which relates with table 'sales_sequence_meta'.

Table 'sales_sequence_meta' sequence table names according to stores and type(order, invoice, shipment, creditmemo, rma).

  • sequence_order_* contains the last inserted order ids
  • sequence_shipment_* contains the last inserted shipment ids
  • sequence_invoice_* contains the last inserted invoice ids
  • sequence_creditmemo_* contains the last inserted creditmemo ids
  • sequence_rma_item_* contains the last inserted rma item ids

Basically this is just for understanding. You need to update the table 'sales_sequence_profile' and related sequence tables.

Problem solved? Click Accept as Solution!

Re: Magento 2 - detect orders that are placed via REST API

Hello @Bhanu Periwal,

 

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 

Re: Magento 2 - detect orders that are placed via REST API

Can someone help me with this?