3

When i call this API,

{{base_url}}index.php/rest/V1/configurable-products/:sku/options/all

I am getting a response like this,

[
  {
    "id": 9,
    "attribute_id": "93",
    "label": "Color",
    "position": 0,
    "values": [
      {
        "value_index": 15
      },
      {
        "value_index": 16
      },
      {
        "value_index": 17
      }
    ],
    "product_id": 19
  },
  {
    "id": 10,
    "attribute_id": "176",
    "label": "side",
    "position": 1,
    "values": [
      {
        "value_index": 18
      },
      {
        "value_index": 19
      }
    ],
    "product_id": 19
  }
]

But i want label for all these value_indexes.Could i get all these values in a single request

2 Answers 2

1

There is an API to get all the option labels:

{{base_url}}/index.php/rest/V1/products/attributes/:attribute_id/options

Example:

{{base_url}}/index.php/rest/V1/products/attributes/93/options

will return

[
  {
    "label": " ",
    "value": ""
  },
  {
    "label": "green",
    "value": "12"
  },
  {
    "label": "yellow",
    "value": "13"
  },
  {
    "label": "red",
    "value": "14"
  }
]
0

You can use this endpoint to fetch multiple attribute sets in a single request /rest/V1/products/attributes

example:

{domain}/rest/V1/products/attributes?search_criteria[filter_groups][0][filters][0][field]=attribute_id&search_criteria[filter_groups][0][filters][0][value]=93,138&search_criteria[filter_groups][0][filters][0][condition_type]=in

response:

    "items": [
        {
            "is_wysiwyg_enabled": false,
            "is_html_allowed_on_front": false,
            "used_for_sort_by": false,
            "is_filterable": true,
            "is_filterable_in_search": false,
            "is_used_in_grid": true,
            "is_visible_in_grid": false,
            "is_filterable_in_grid": true,
            "position": 0,
            "apply_to": [
                "simple",
                "virtual",
                "configurable"
            ],
            "is_searchable": "1",
            "is_visible_in_advanced_search": "1",
            "is_comparable": "1",
            "is_used_for_promo_rules": "0",
            "is_visible_on_front": "0",
            "used_in_product_listing": "0",
            "is_visible": true,
            "scope": "global",
            "attribute_id": 93,
            "attribute_code": "color",
            "frontend_input": "select",
            "entity_type_id": "4",
            "is_required": false,
            "options": [
                {
                    "label": " ",
                    "value": ""
                },
                {
                    "label": "blue",
                    "value": "8"
                },
                {
                    "label": "red",
                    "value": "9"
                },
                {
                    "label": "black",
                    "value": "10"
                },
                {
                    "label": "white",
                    "value": "11"
                }
            ],
            "is_user_defined": true,
            "default_frontend_label": "Color",
            "frontend_labels": [],
            "backend_type": "int",
            "source_model": "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table",
            "default_value": "",
            "is_unique": "0",
            "validation_rules": []
        },
        {
            "is_wysiwyg_enabled": false,
            "is_html_allowed_on_front": true,
            "used_for_sort_by": false,
            "is_filterable": false,
            "is_filterable_in_search": false,
            "is_used_in_grid": true,
            "is_visible_in_grid": true,
            "is_filterable_in_grid": true,
            "position": 0,
            "apply_to": [],
            "is_searchable": "0",
            "is_visible_in_advanced_search": "0",
            "is_comparable": "0",
            "is_used_for_promo_rules": "0",
            "is_visible_on_front": "0",
            "used_in_product_listing": "0",
            "is_visible": true,
            "scope": "global",
            "attribute_id": 138,
            "attribute_code": "simple_size",
            "frontend_input": "select",
            "entity_type_id": "4",
            "is_required": true,
            "options": [
                {
                    "label": " ",
                    "value": ""
                },
                {
                    "label": "small",
                    "value": "12"
                },
                {
                    "label": "medium",
                    "value": "13"
                },
                {
                    "label": "large",
                    "value": "14"
                }
            ],
            "is_user_defined": true,
            "default_frontend_label": "simple_size",
            "frontend_labels": [
                {
                    "store_id": 1,
                    "label": "Size"
                }
            ],
            "backend_type": "int",
            "source_model": "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table",
            "default_value": "",
            "is_unique": "0",
            "validation_rules": []
        }
    ],
    "search_criteria": {
        "filter_groups": [
            {
                "filters": [
                    {
                        "field": "attribute_id",
                        "value": "93,138",
                        "condition_type": "in"
                    }
                ]
            }
        ]
    },
    "total_count": 2
}

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.