I am using Magento 2.1.6 CE
and also am using default rest api's
for create mobile app. When I get product by sku
I get all the details of the particular product including custom attributes also.
But in custom attributes I have some attributes like color
attribute (i.e. dropdown and filterable). I have various options for color
attribute like Blue, Green, Red
etc
When am requesting /V1/products/{{sku}}
it shows custom attributes like following, (it shows option_id
instead of option_value
).
....
{
"attribute_code": "color",
"value": "11"
},
....
But I need this like the following,
....
{
"attribute_code": "color",
"value": "Green"
},
....
How can I get this done?
Please suggest me is there any default options available to done this.
Best Answer
Please follow the below steps from custom module if it success then you can customize whatever you want.
Note:- we are creating a new product attribute and associating the required data to the product attribute.
Step 1:- create a new module using silk software tool ex:- CompanyName_ModuleName
Step 2:- create a new product attribute using install script (or) admin end.
Step 3:- create a webapi.xml => /app/code/CompanyName/ModuleName/etc/webapi.xml
Step 4: app/code/CompanyName/ModuleName/etc/di.xml
Step 5: app/code/CompanyName/ModuleName/Api/ProductsInterface.php
Step 6: app/code/CompanyName/ModuleName/Model/Products.php
Step 7: after did the changes make sure use di:compile
Step 8: open postman application for getting the result as shown below
Method: GET
UrL:- http://website.com/rest/V1/product/24-MB04
Step 9: Output