0

When I do GET /rest/V1/products/prodID, in response (custom_attributes field) I have

{
     "attribute_code": "category_ids",
     "value": [
        "2",
        "3",
        "20"
      ]
 }

but if i do GET /rest/V1/products?searchCriteria, and get product list, "custom_attributes" don't have "attribute_code": "category_ids" what can i do for have "category_ids" in magento rest api response?

2
  • Is this a custom attribute? If so, you would probably have to go via the extension_attributes path to add it to the correct controller. See here as an example: atwix.com/development/…
    – tecjam
    Commented Jan 24, 2019 at 16:20
  • If you mean the existing attribute you may just need to add it to the correct group in the catalog_attributes.xml via a custom module. <group name="catalog_product"><attribute name="category_ids" /></group>
    – tecjam
    Commented Jan 24, 2019 at 16:26

1 Answer 1

0

The getList on Magento\Catalog\Model\ProductRepository which provides you GET /rest/V1/products?searchCriteria already supported your response with category_ids

See

https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Catalog/Model/ProductRepository.php#L685

You don't have to do anything from this, you'd just make sure products were belong to some categories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.