简体   繁体   English

Magento 2 Rest API获得产品类别

[英]Magento 2 Rest API get Product Category

I try to get the sku,name and category_ids for a certain product via REST call. 我尝试通过REST调用获取特定产品的sku,名称和category_id。 Unfortunately I do not know how to only get the category_ids 不幸的是我不知道如何只获得category_ids

I use following REST call: /V1/products?searchCriteria[filterGroups][0][filters][0][field]=sku&fields=items[sku,name,custom_attributes]&searchCriteria[filterGroups][0][filters][0][value]=66-110101000 我使用以下REST调用:/ V1 / products?searchCriteria [filterGroups] [0] [filters] [0] [field] = sku&fields = items [sku,name,custom_attributes]&searchCriteria [filterGroups] [0] [filters] [0 ] [值] = 66-110101000

I always receive a response like this: 我总是收到这样的答复:

{
"items": [
    {
        "sku": "66-110101000",
        "name": "Fruchtgummi-Standardformen 10 g (100 Stück)",
        "custom_attributes": [
            {
                "attribute_code": "description",
                "value": "Fruchtgummi-Standardformen mit 10 % Fruchtgehalt aus Fruchtsaftkonzentrat, natürlichen Aromen und färbenden Pflanzenauszügen, farblich und geschmacklich bunt gemischt, in glänzend- oder matt-kaschiertem transparentem alternativ weißem Werbetütchen verpackt."
            },
            {
                "attribute_code": "color",
                "value": "6923"
            },
            {
                "attribute_code": "category_ids",
                "value": [
                    "104"
                ]
            },
            {
                "attribute_code": "has_options",
                "value": "0"
            },
            {
                "attribute_code": "tax_class_id",
                "value": "2"
            },
            {
                "attribute_code": "gift_message_available",
                "value": "0"
            },
            {
                "attribute_code": "color_exact",
                "value": "2508"
            },
            {
                "attribute_code": "package_type",
                "value": "Karton"
            },
            {
                "attribute_code": "shelf_life",
                "value": "ca. 12 Monate bei sachgerechter Lagerung"
            },
            {
                "attribute_code": "supplier_sku",
                "value": "110101000"
            },
            {
                "attribute_code": "product_name_supplier",
                "value": "Fruchtgummi-Standardformen 10 g (100 Stück)"
            },
            {
                "attribute_code": "customs_tariff_number",
                "value": "17049065"
            },
            {
                "attribute_code": "dimensions",
                "value": "ca. 85 x 60 mm mm"
            },
            {
                "attribute_code": "sw_featured",
                "value": "0"
            },
            {
                "attribute_code": "keyword_variable",
                "value": "Werbeartikel"
            },
            {
                "attribute_code": "weight_with_package",
                "value": "0.01"
            },
            {
                "attribute_code": "product_weight",
                "value": "1"
            },
            {
                "attribute_code": "use_in_crosslinking",
                "value": "1"
            },
            {
                "attribute_code": "in_html_sitemap",
                "value": "1"
            },
            {
                "attribute_code": "in_xml_sitemap",
                "value": "1"
            }
        ]
    }
]

} }

All I am interessted in is to display sku, name and category_ids. 我感兴趣的是显示sku,名称和category_ids。 Hope you can help me how to change my API call. 希望您能帮助我如何更改我的API调用。 Thanks in advance! 提前致谢!

You can use the following endpoint for the desired product attributes:- 您可以将以下端点用于所需的产品属性:-

GET http:///rest/default/V1/products/24-MB01?fields=sku,price,name GET http:/// rest / default / V1 / products / 24-MB01?fields = sku,price,name

Please refer:- 请参考:

https://devdocs.magento.com/guides/v2.1/rest/retrieve-filtered-responses.html https://devdocs.magento.com/guides/v2.1/rest/retrieve-filtered-responses.html

OR 要么

You have to write your custom endpoint for the this. 您必须为此编写自定义端点。 There is no predefined endpoint for the custom attribute selection for the product. 没有用于产品的定制属性选择的预定义端点。

To developer custom endpoint you can follow the tutorial 要开发人员自定义端点,您可以按照教程进行操作

https://www.thirdandgrove.com/creating-custom-rest-api-magento2 https://www.thirdandgrove.com/creating-custom-rest-api-magento2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM