Hello Magento Friends,

I hope all are doing great. Today I will be explaining Magento 2: How to Get Order Details with Custom Extension Attributes using REST API. In case you missed reviewing our previous blog, How to Get Region Code by Region ID in Magento 2.

Introduction:

When customers purchase products, Magento 2 handles various entities, like products, customers, and orders. Magento provides different ways to fetch that entity data. One of them is to Get Order Details using REST API in Magento 2.

But suppose we have used some custom extension attributes with orders or products or customers. In that case, Magento default does not return that custom extension attributes values while we get details using the REST API.

No worries! With the below code’s help, we will learn How to Get Order Details with Custom Extension Attributes using REST API. So let us get started.

Steps to Get Order Details with Custom Extension Attributes using REST API in Magento 2:

Step 1: Create extension_attributes.xml file inside app\code\Vendor\Extension\etc folder and add the code as mentioned below:

Step 2: Next create events.xml file inside app\code\Vendor\Extension\etc folder and add the below code:

Step 3: Next create OrderloadAfter.php file inside app\code\Vendor\Extension\Observer folder and add the below-mentioned code:

Step 4: Next clear the generated folder from Magento root and clear cache.

Step 5: Finally, execute the getOrderDetails.php script file inside your Magento root folder and add the below code. (You can use this code in your Magento file system. e.g., you can even use it in your custom module).

That’s it!

Conclusion:

Accordingly, you can Get Order Details with Custom Extension Attributes using REST API in Magento 2.Mention your difficulties in the comment part. I will be happy to solve it.

Keep Learning! Stay informed!

Happy Coding

[Total: 7   Average: 5/5]