Magento 2 API

Learn How to Add Custom Parameter in Magento 2 Order API

Today, I will explain you, how you can include custom parameter (external order id and channel) in Magento 2 Order API, which you can get or set in order by using Magento Order API.

As you know, in Magento, we have to develop custom modules in order to add any extra feature as per your requirements. So, you have to create a module to implement this feature.

Here, I am skipping the basic Module structure.

You have to create a Registration.php and module.xml before using the codes below.


Create extension_attributes.xml in app\code\Ids\CheckOrder\etc\

In order to add external_order_id and channel in Order API, we have to create extension attributes, we will use these attributes to send parameters from Quote to Order.



Create di.xml in app\code\Ids\CheckOrder\etc\

Further, we will create di.xml to create OrderRepositoryPlugin and we are creating this Plugin to inject custom parameter data to order API.


Magento 2 Development



Create OrderRepositoryPlugin.php in app\code\Ids\CheckOrder\Plugin\

Here, we will inject our custom parameters in Order API by using two methods afterGet and afterGetList. afterGet is used to set custom parameters and afterGetList is used to get custom parameters.


Did You Know: How to Use the Declarative Schema in Magento 2? Here is a Guide


Contributed By:

Sharika Dubey

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge