cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 rest custom options text values (label/title)

Highlighted

Magento 2 rest custom options text values (label/title)

Hi, I was wondering if there was a way to get text values for custom options on a configurable product.

 

My product:

 

GET /rest/V1/orders/items/156
{
    "amount_refunded": 0,
    "applied_rule_ids": "2",
    "base_amount_refunded": 0,
    "base_discount_amount": 0,
    "base_discount_invoiced": 0,
    "base_discount_tax_compensation_amount": 0,
    "base_discount_tax_compensation_invoiced": 0,
    "base_original_price": 8.88,
    "base_price": 103.88,
    "base_price_incl_tax": 112.45,
    "base_row_invoiced": 103.88,
    "base_row_total": 103.88,
    "base_row_total_incl_tax": 112.45,
    "base_tax_amount": 8.57,
    "base_tax_invoiced": 8.57,
    "created_at": "2018-08-30 14:48:41",
    "discount_amount": 0,
    "discount_invoiced": 0,
    "discount_percent": 0,
    "free_shipping": 0,
    "discount_tax_compensation_amount": 0,
    "discount_tax_compensation_invoiced": 0,
    "is_qty_decimal": 0,
    "is_virtual": 0,
    "item_id": 156,
    "name": "Configurable product",
    "no_discount": 0,
    "order_id": 82,
    "original_price": 8.88,
    "price": 103.88,
    "price_incl_tax": 112.45,
    "product_id": 2072,
    "product_type": "configurable",
    "qty_canceled": 0,
    "qty_invoiced": 1,
    "qty_ordered": 1,
    "qty_refunded": 0,
    "qty_shipped": 0,
    "quote_item_id": 108,
    "row_invoiced": 103.88,
    "row_total": 103.88,
    "row_total_incl_tax": 112.45,
    "row_weight": 0,
    "sku": "config-prod-Orange",
    "store_id": 1,
    "tax_amount": 8.57,
    "tax_invoiced": 8.57,
    "tax_percent": 8.25,
    "updated_at": "2018-08-30 14:48:55",
    "weee_tax_applied": "[]",
    "weight": 1,
    "product_option": {
        "extension_attributes": {
            "custom_options": [
                {
                    "option_id": "2",
                    "option_value": "1"
                }
            ],
            "configurable_item_options": [
                {
                    "option_id": "93",
                    "option_value": 56
                }
            ]
        }
    }
}

 

 

I can get the configurable_items_options text here:

 

GET /rest/V1/products/attributes/93
{
    "is_wysiwyg_enabled": false,
    "is_html_allowed_on_front": true,
    "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": "0",
    "is_visible_in_advanced_search": "0",
    "is_comparable": "0",
    "is_used_for_promo_rules": "1",
    "is_visible_on_front": "0",
    "used_in_product_listing": "1",
    "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": "Black",
            "value": "49"
        },
        {
            "label": "Blue",
            "value": "50"
        },
        {
            "label": "Brown",
            "value": "51"
        },
        {
            "label": "Gray",
            "value": "52"
        },
        {
            "label": "Green",
            "value": "53"
        },
        {
            "label": "Lavender",
            "value": "54"
        },
        {
            "label": "Multi",
            "value": "55"
        },
        {
            "label": "Orange",
            "value": "56"
        },
        {
            "label": "Purple",
            "value": "57"
        },
        {
            "label": "Red",
            "value": "58"
        },
        {
            "label": "White",
            "value": "59"
        },
        {
            "label": "Yellow",
            "value": "60"
        }
    ],
    "is_user_defined": true,
    "default_frontend_label": "Color",
    "frontend_labels": null,
    "backend_type": "int",
    "source_model": "Magento\\Eav\\Model\\Entity\\Attribute\\Source\\Table",
    "default_value": "49",
    "is_unique": "0",
    "validation_rules": []
}

 

 

However, this does not work with custom_options:

GET /rest/V1/products/attributes/2

{
    "message": "Attribute with attributeCode \"%1\" does not exist.",
    "parameters": [
        "2"
    ]
}

I can get the custom options from the PARENT item here: 

GET /rest/V1/products/config-prod/options/

[
    {
        "product_sku": "config-prod",
        "option_id": 2,
        "title": "Fee Type",
        "type": "radio",
        "sort_order": 1,
        "is_require": true,
        "max_characters": 0,
        "image_size_x": 0,
        "image_size_y": 0,
        "values": [
            {
                "title": "White Glove Delivery",
                "sort_order": 1,
                "price": 95,
                "price_type": "fixed",
                "option_type_id": 1
            },
            {
                "title": "Inside Delivery",
                "sort_order": 2,
                "price": 35,
                "price_type": "fixed",
                "option_type_id": 2
            },
            {
                "title": "Standard",
                "sort_order": 3,
                "price": null,
                "price_type": null,
                "option_type_id": 3
            }
        ]
    }
]

However, this does not work when using the configurable SKU:

GET /rest/V1/products/config-prod-Orange/options/

[]

There is also no way of getting the parent SKU from the item from what I can tell.

 

1. So, is there a way to either get the parent SKU from a child SKU?

OR

2. Is there a way to get the text values for custom options similar to 

/rest/V1/products/attributes/93

 

3 REPLIES 3
Highlighted

Re: Magento 2 rest custom options text values (label/title)

Did you ever make any progress with this?

Highlighted

Re: Magento 2 rest custom options text values (label/title)

/rest/V1/products/attributes/manufacturer/options

 

try using the above API, it worked for me.

Highlighted

Re: Magento 2 rest custom options text values (label/title)