Magento – Magento 2 REST API get all product details

magento2rest api

I cannot seem to retrieve description, meta_title, meta_description etc. when using the REST API.

I have tried the below API call with no luck:

https://domain.com/rest/all/V1/products/123456

{
    "id": 41314,
    "sku": "123456",
    "name": "Some product name",
    "attribute_set_id": 10,
    "price": 500,
    "status": 2,
    "visibility": 4,
    "type_id": "simple",
    "created_at": "2017-06-06 01:34:08",
    "updated_at": "2017-06-06 01:34:08",
    "weight": 1,
    "extension_attributes": {
        "website_ids": [
            1,
            2,
            3,
            4
        ],
        "category_links": [
            {
                "position": 1,
                "category_id": "483"
            },
            {
                "position": 1,
                "category_id": "307"
            },
            {
                "position": 1,
                "category_id": "434"
            },
            {
                "position": 1,
                "category_id": "534"
            }
        ],
        "stock_item": {
            "item_id": 46746,
            "product_id": 41314,
            "stock_id": 1,
            "qty": 0,
            "is_in_stock": false,
            "is_qty_decimal": false,
            "show_default_notification_message": false,
            "use_config_min_qty": true,
            "min_qty": 0,
            "use_config_min_sale_qty": 1,
            "min_sale_qty": 1,
            "use_config_max_sale_qty": true,
            "max_sale_qty": 10000,
            "use_config_backorders": true,
            "backorders": 0,
            "use_config_notify_stock_qty": true,
            "notify_stock_qty": 1,
            "use_config_qty_increments": true,
            "qty_increments": 0,
            "use_config_enable_qty_inc": true,
            "enable_qty_increments": false,
            "use_config_manage_stock": true,
            "manage_stock": true,
            "low_stock_date": "2017-11-23 15:33:03",
            "is_decimal_divided": false,
            "stock_status_changed_auto": 1
        }
    },
    "product_links": [],
    "options": [],
    "media_gallery_entries": [],
    "tier_prices": [],
    "custom_attributes": [
        {
            "attribute_code": "special_price",
            "value": "0.0000"
        },
        {
            "attribute_code": "special_from_date",
            "value": "2017-06-06 00:00:00"
        },
        {
            "attribute_code": "special_to_date",
            "value": "2017-06-07 00:00:00"
        },
        {
            "attribute_code": "news_from_date",
            "value": "2017-06-05 00:00:00"
        },
        {
            "attribute_code": "news_to_date",
            "value": "2017-06-07 00:00:00"
        },
        {
            "attribute_code": "custom_design_from",
            "value": "2017-06-06 00:00:00"
        },
        {
            "attribute_code": "custom_design_to",
            "value": "2017-06-08 00:00:00"
        },
        {
            "attribute_code": "category_ids",
            "value": [
                "483",
                "307",
                "434",
                "534"
            ]
        },
        {
            "attribute_code": "options_container",
            "value": "container2"
        },
        {
            "attribute_code": "required_options",
            "value": "0"
        },
        {
            "attribute_code": "has_options",
            "value": "0"
        },
        {
            "attribute_code": "url_key",
            "value": "some-url"
        },
        {
            "attribute_code": "msrp_display_actual_price_type",
            "value": "0"
        },
        {
            "attribute_code": "tax_class_id",
            "value": "2"
        },
        {
            "attribute_code": "gift_message_available",
            "value": "2"
        }
    ]
}

Best Answer

Hello Please find the below screen shot for Your Requirement.

enter image description here

First You need to Override the Core files in Your module di.xml

To display those description, meta_description and meta_title.

Note:Copy whole default core file and add the below part in respective File code.

File Path:app/code/extension_Name/Module_name/Model/Product.php

/**
     * Get product name
     *
     * @return string
     * @codeCoverageIgnoreStart
     */
    public function getDescription()
    {
        return $this->_getData(self::DESCRIPTION);
    }

    /**
     * Get product name
     *
     * @return string
     * @codeCoverageIgnoreStart
     */
    public function getMetaDescription()
    {
        return $this->_getData(self::META_DESCRIPTION);
    }

    /**
     * Get product name
     *
     * @return string
     * @codeCoverageIgnoreStart
     */
    public function getMetaTitle()
    {
        return $this->_getData(self::META_TITLE);
    }

     /**
     * Set product description
     *
     * @param string $description
     * @return $this
     */
    public function setDescription($description)
    {
        return $this->setData(self::DESCRIPTION, $description);
    }

     /**
     * Set product meta_description
     *
     * @param string $meta_description
     * @return $this
     */
    public function setMetaDescription($meta_description)
    {
        return $this->setData(self::META_DESCRIPTION, $meta_description);
    }

     /**
     * Set product meta_title
     *
     * @param string $meta_title
     * @return $this
     */
    public function setMetaTitle($meta_title)
    {
        return $this->setData(self::META_TITLE, $meta_title);
    }

File Path:app/code/extension_Name/Module_name/Api/Data/ProductInterface.php

in the above File just place the below code as per requirement

 const DESCRIPTION = 'description';

    const META_DESCRIPTION = 'meta_description';

    const META_TITLE = 'meta_title';

   /**
     * Product description
     *
     * @return string|null
     */
    public function getDescription();

    /**
     * Set product description
     *
     * @param string $description
     * @return $this
     */
    public function setDescription($description);

    /**
     * Product description
     *
     * @return string|null
     */
    public function getMetaDescription();

    /**
     * Set product meta_description
     *
     * @param string $meta_description
     * @return $this
     */
    public function setMetaDescription($meta_description);

     /**
     * Product description
     *
     * @return string|null
     */
    public function getMetaTitle();

    /**
     * Set product meta_title
     *
     * @param string $meta_title
     * @return $this
     */
    public function setMetaTitle($meta_title);