Create the first simple product using cURL
Adjust environment IDs and product details
Create the first simple product by using the API to send the following POST request using cURL.
Before submitting the request, update the example with values for your environment.
- Change
"attribute-set": 10
to replace10
with the attribute set ID from your environment. - Change
"value": "13"
to replace13
with the value from your environment.
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=aff63a1634f6f1a773e7a4894bf1a55c' \
--data '{
"product": {
"sku": "Kids-Hawaiian-Ukulele-red",
"name": "Kids Hawaiian Ukulele Red",
"attribute_set_id": 10,
"price": 12.50,
"status": 1,
"visibility": 1,
"type_id": "simple",
"weight": "0.5",
"extension_attributes": {
"stock_item": {
"qty": "10",
"is_in_stock": true
}
},
"custom_attributes": [
{
"attribute_code": "color",
"value": "13"
}
]
}
}
'
Create the second simple product using cURL
Create the second simple product by using the API to send the following POST request using cURL.
Before submitting the request, update the example with values for your environment.
- Change
"attribute_set_id": 10,
and replace10
with the attribute set id from in your environment. - Change
"value": "14"
and replace14
with the value from your environment.
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=aff63a1634f6f1a773e7a4894bf1a55c' \
--data '{
"product": {
"sku": "Kids-Hawaiian-Ukulele-Blue",
"name": "Kids Hawaiian Ukulele Blue",
"attribute_set_id": 10,
"price": 15,
"status": 1,
"visibility": 1,
"type_id": "simple",
"weight": "0.5",
"extension_attributes": {
"stock_item": {
"qty": "20",
"is_in_stock": true
}
},
"custom_attributes": [
{
"attribute_code": "color",
"value": "14"
}
]
}
}
'
Create the third simple product using cURL
Create the third simple product by sending the following POST request using cURL.
Before submitting the request, update the example with values for your environment.
- Change
"attribute_set_id": 10,
to replace10
with the attribute set ID from your environment. - Change
"value": "15"
and replace15
with the value from your environment.
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=aff63a1634f6f1a773e7a4894bf1a55c' \
--data '{
"product": {
"sku": "Kids-Hawaiian-Ukulele-Green",
"name": "Kids Hawaiian Ukulele Green",
"attribute_set_id": 10,
"price": 25,
"status": 1,
"visibility": 1,
"type_id": "simple",
"weight": "0.5",
"extension_attributes": {
"stock_item": {
"qty": "30",
"is_in_stock": true
}
},
"custom_attributes": [
{
"attribute_code": "color",
"value": "15"
}
]
}
}
'
Create an empty configurable product using cURL
Create an empty configurable product by sending the following POST request using cURL.
Before submitting the request, update the example with values for your environment.
- Change
"attribute_set_id": 10,
and replace10
with the attribute set id from your environment. - Change
"value": "93"
and replace93
with the value from your environment.
curl --location '{{your.url.here}}/rest/default/V1/products' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=aff63a1634f6f1a773e7a4894bf1a55c' \
--data '{
"product": {
"sku": "Kids-Hawaiian-Ukulele",
"name": "Kids Hawaiian Ukulele",
"attribute_set_id": 10,
"status": 1,
"visibility": 4,
"type_id": "configurable",
"weight": "0.5",
"custom_attributes": [
{
"attribute_code": "color",
"value": "93"
}
]
}
}'
Set the options available for the configurable product
Set the options available for the configurable product by sending the following POST request using cURL.
Before submitting the request, change "attribute_id": 93,
to replace 93
with the attribute id from your environment.
curl --location '{{your.url.here}}/rest/default/V1/configurable-products/Kids-Hawaiian-Ukulele/options' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=aff63a1634f6f1a773e7a4894bf1a55c' \
--data '{
"option": {
"attribute_id": "93",
"label": "Color",
"position": 0,
"is_use_default": true,
"values": [
{
"value_index": 9
}
]
}
}'
If you forget to set the options for the configurable product (parent), you get an error when you try to associate a child product to the configurable product. The error message is similar to the following example:
{"message":"The parent product doesn't have configurable product options.","trace":"#0 [internal function]: Magento\\ConfigurableProduct\\Model\\LinkManagement->addChild('Kids-Hawaiian-U...'}
Link the child product to the configurable
Now, you have created three simple products:
"Kids Hawaiian Ukulele Red"
,"Kids-Hawaiian-Ukulele-Blue"
"Kids-Hawaiian-Ukulele-Green"
Add these simple products as children of the configurable product by sending the following POST request. Submit a separate request for each product.
For each request, update the childSKU
value with the value for the child product you are adding. The following example assigns the simple product kids-Hawaiian-Ukulele-red
to the configurable product with the SKU Kids-Hawaiian-Ukulele-red
.
curl --location '{{your.url.here}}rest/default/V1/configurable-products/Kids-Hawaiian-Ukulele/child' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{Your Bearer Token}}' \
--header 'Cookie: PHPSESSID=aff63a1634f6f1a773e7a4894bf1a55c' \
--data '{
"childSku": "Kids-Hawaiian-Ukulele-red"
}
'
Get a configurable product using cURL
Now that you have created a configurable product with three assigned child SKUs. You can see the linked IDs for the assigned products by sending the following GET request using cURL. This request returns detailed information about the configurable product.
...
"configurable_product_links": [
155,
157,
156
]
...
The following uses the GET method
curl --location '{{your.url.here}}/rest/default/V1/products/Kids-Hawaiian-Ukulele' \
--header 'Authorization: Bearer {{Your Bearer Token}}'
Get the children product associated to a configurable product
Return only the children associated with the configurable product by sending the following GET request. The response will include all the attributes for the child product including SKU and price.
The following uses the GET method
curl --location '{{your.url.here}}/rest/default/V1/configurable-products/kids-hawaiian-ukulele/children' \
--header 'Authorization: Bearer {{Your Bearer Token}}'
Delete or remove a child product from the parent configurable
You can remove a child product from a configurable product without deleting the product from the catalog by sending the following DELETE request using cURL.
curl --location --request DELETE '{{your.url.here}}/rest/default/V1/configurable-products/Kids-Hawaiian-Ukulele/children/Kids-Hawaiian-Ukulele-Blue' \
--header 'Authorization: Bearer {{Your Bearer Token}}'
Additional resources
Commerce
- Commerce Tutorials
- Adobe Commerce Cloud
- Getting Started
- Global Reference Architecture
- Help and support
- Edge Delivery Services
- Webinars and events
- GraphQL and REST
- Adobe Developer App Builder
- Store Administration
- Customer Management
- Catalog Management
- Content Management
- Marketing Tools
- Orders and Fulfillment
- B2B for Adobe Commerce
- Tools and External services
- Commerce Intelligence
- Commerce Upgrades
- Back-end Development
- Native Front-end Luma Development
- Headless Architecture