Create a configurable product tutorial

Step 4. Define configurable product options

Now that we’ve created all the Champ Tee products, we need to assign size as the configurable attribute and link the simple products to the configurable product.

Set the configurable attribute

The POST V1/configurable-products/:sku/options call assigns the specified attribute_id to be the configurable attribute. Specify the sku of the configurable product in the URI.

The value assigned to the value_index must be unique within the system.

Endpoint:

POST <host>/rest/default/V1/configurable-products/MS-Champ/options

Payload:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "option": {
    "attribute_id": "141",
    "label": "Size",
    "position": 0,
    "is_use_default": true,
    "values": [
      {
        "value_index": 9
      }
    ]
  }
}

Response:

A configurable option ID number, such as "335".

The call to link a simple (child) product to the configurable product accepts only one childSku value. You must repeat this call for the MS-Champ-M and MS-Champ-L products.

Endpoint:

POST <host>/rest/default/V1/configurable-products/MS-Champ/child

Payload:

1
2
3
{
  "childSku": "MS-Champ-S"
}

Response:

true

Verify this step

  • Log in to the Luma website and select Catalog > Products. Click on the Champ Tee configurable product and expand the Configurations section.

Product page with configurable and simple products

  • On the Luma storefront page, search for Champ.

Search results

  • Call GET /V1/products/MS-Champ. The response includes the configurable_product_options and configurable_product_links arrays.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
"configurable_product_options": [
    {
        "id": 338,
        "attribute_id": "141",
        "label": "Size",
        "position": 0,
        "values": [
            {
                "value_index": 168
            },
            {
                "value_index": 169
            },
            {
                "value_index": 170
            }
        ],
        "product_id": 2078
    }
],
"configurable_product_links": [
    2079,
    2080,
    2081
]
},
...