How to Get Value of Custom Attribute on Magento 2 Rest API

Get Value of Custom Attribute on Magento 2 Rest API

Magento 2 REST API is the best way of developing the cross-platform app to communicate with your Magento 2 stores. While developing an app, you would require to get value of custom attribute on Magento 2 REST API and use this further in the app. Today, I have come up with the complete guide to get value ofcustom attribute on Magento 2 REST API.

Steps to Get Value of Custom Attribute on Magento 2 Rest API:

  1. Create/Add a new column in ‘sales_order‘ table and set value for the existing order.
  2. Create a new file at app\code\Vendor\Module\etc\extension_attributes.xml and put the below code:
  3. Create event.xml at app\code\Vendor\Module\etc\events.xml
  4. Create OrderLoadAfter.php at app\code\Vendor\Module\Observer\Sales\OrderLoadAfter.php
  5. Clear the cache and delete the folder to apply function.

After getting an order on Magento 2 Rest API, you can see the custom attribute in the response.

That’s all about getting value of custom attribute on Magento 2 REST API. Let me know which custom attribute value did you get using the code above and how you used the value in your app. Don’t forget to share your questions in the comment section below and I’ll be helping you in the best possible way. Share the tutorial with your fellow Magento friends to help them out!

5
(based on 7 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply