Magento – Magento 2 Rest Api V1/products missing extension attributes

cataloginventorymagento2productsrest

I am calling the Rest API V1/products to get the product list from Magento 2 store

Request:

 http://{myMagentohost}/Magento/index.php/rest/V1/products?searchCriteria[currentPage]=1&searchCriteria[pageSize]=1

Response:

 {"items": [ { "id": 1,"sku": "24-MB01","name": "Joust Duffle Bag","attribute_set_id": 15,"price": 34,"status": 1,"visibility": 4,"type_id": "simple","created_at": "2017-06-13 09:36:11","updated_at": "2017-06-13 09:36:11","product_links": [{"sku": "24-MB01", "link_type": "upsell","linked_product_sku": "24-MB03","linked_product_type": "simple","position": null,"extension_attributes": []},{"sku": "24-B01","link_type": "upsell","linked_product_sku": "24-WB04","linked_product_type": "simple","position": null,"extension_attributes": []}],"options": [],"tier_prices": [],"custom_attributes": [{"attribute_code": "description","value": "<p>The sporty Joust Duffle Bag can't be beat - ot in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.<p>\n<ul>\n<li>Dual top handles.</li>\n<li>Adjustable shoulder strap.</li>\n<li>Full-length zipper.</li>\n<li>L 29\" x W 13\" x H 11\".</li>\n</ul>"},{"attribute_code": "image","value": "/m/b/mb01-blue-0.jpg"},{"attribute_code": "small_image","value": "/m/b/mb01-blue-0.jpg"},{"attribute_code": "thumbnail","value": "/m/b/mb01-blue-0.jpg"},{"attribute_code": "url_key","value": "joust-duffle-bag"}]}],"search_criteria": {"filter_groups": [],"page_size": 1,"current_page": 1},"total_count": 2046}

Now according to the Magento 2 Rest API swagger documentation,
catalogProductRepositoryV1, GET /V1/products in response it shows the extension_attributes but when I actually call this api from postman extension_attributes is missing.

I search for it but no appropriate solution is available.

Can anyone help in this matter?

Thanks!

Best Answer

Perhaps you do not have permission to see any extension attributes so it's left empty or omitted entirely?

For example, if your extension_attributes.xml looked like this:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Catalog\Api\Data\ProductInterface">
        <attribute code="stock_item" type="Magento\CatalogInventory\Api\Data\StockItemInterface">
            <resources>
                <resource ref="Magento_CatalogInventory::cataloginventory"/>
            </resources>
        </attribute>
    </extension_attributes>
</config>

Only admins with the Magento_CatalogInventory::cataloginventory permission will see a stock_item key in the API response.

{
  "sku": "tshirt1",
  "price": "20.00",
  "description": "New JSmith design",
  "extension_attributes": {
    "logo size": "small",
    "stock_item" : {
      "status" : "in_stock"
      "quantity": 70
    }
  },
  "custom_attributes": {
    "artist": "James Smith"
  }
}

http://devdocs.magento.com/guides/v2.0/extension-dev-guide/attributes.html#ext-auth

Related Topic