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:
Copied to your clipboard{"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".
Link the simple products to the configurable product
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:
Copied to your clipboard{"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.
- On the Luma storefront page, search for
Champ.
- Call
GET /V1/products/MS-Champ. The response includes theconfigurable_product_optionsandconfigurable_product_linksarrays.
Copied to your clipboard..."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]},...

