EAV vs Extension Attributes in Magento 2 WebAPI: Why Your Data May Be Missing

Introduction

Magento 2 provides a flexible system to store product data using EAV (Entity-Attribute-Value) and allows adding custom data via extension attributes. However, many developers notice that while EAV attribute values are available in the WebAPI payload, extension attribute values are often missing. In this article, we’ll explain why this happens and how to fix it.

What Are EAV Attributes?

EAV attributes are the standard product attributes stored in Magento's database tables like catalog_product_entity_*. These attributes are automatically available in WebAPI payloads if configured correctly.

{
    "id": 1,
    "sku": "product-sku",
    "name": "Product Name",
    "price": 299.99,
    "color": "Red"
}

In this example, color is an EAV attribute and comes directly in the API response.

What Are Extension Attributes?

Extension attributes are custom data objects added to Magento entities via extension_attributes.xml. They are not part of the core EAV tables and therefore do not automatically appear in API responses.

Example of missing extension attribute in API payload:

{
    "id": 1,
    "sku": "product-sku",
    "name": "Product Name",
    "price": 299.99
    // "manufacturer_info" is missing
}

To include extension attributes in WebAPI responses, you must populate them manually via code.

How to Make Extension Attributes Available in WebAPI

  1. Declare the extension attribute in extension_attributes.xml.
  2. Implement getter and setter methods in the entity's data interface.
  3. Use a plugin or observer to populate the attribute when the repository method is called.
  4. Ensure it is exposed via webapi.xml if necessary.

Example of a plugin to populate an extension attribute:

namespace Vendor\Module\Plugin;

use Magento\Catalog\Api\ProductRepositoryInterface;

class ProductExtensionAttributePlugin
{
    public function afterGet(
        ProductRepositoryInterface $subject,
        \Magento\Catalog\Api\Data\ProductInterface $product
    ) {
        $extensionAttributes = $product->getExtensionAttributes();
        $extensionAttributes->setManufacturerInfo('ABC Manufacturer');
        $product->setExtensionAttributes($extensionAttributes);
        return $product;
    }
}

Key Takeaways

  • EAV attributes → automatically available in WebAPI responses.
  • Extension attributes → require manual population in code.
  • Without a plugin or repository modification, extension attributes will be missing in API payloads.

By understanding the difference between EAV and extension attributes, Magento 2 developers can ensure their custom data is correctly exposed in WebAPI responses.