Create a simple product tutorial
A simple product in the RCE is a physical product that is shipped to a customer. A simple product might be, for example, a lamp, or a vacuum cleaner. It has no options attached to it such as size, colour or material.
Each simple product will have its own unique SKU, its own unique URL, and its own inventory count (assuming the store is actively managing inventory levels).
Resources
https://docs.rezolve.com/rceapidocs/
Step 1. Plan the product
To create a configurable product programmatically, you’ll need to know the following:
- The attribute names and values defined in the attribute set assigned to the configurable product.
- The categories numbers assigned to the configurable product.
- Which attributes to use as the configuration options.
Since this tutorial uses the sample data, we can take advantage of the options that the Top attribute set provides. This attribute set contains attributes that describe the fabric, sleeve length, and other characteristics that are specific to clothing. It also includes EAV attributes such as size and color, which are commonly available to all types of physical products.
The size of the t-shirt will be the configurable aspect of this product. Therefore, we’ll create a simple product for each size (Small, Medium, and Large).
Define product characteristics
The following table lists the general characteristics of men’s t-shirt we’re creating. These items are among those listed on the New Product page in Admin when the Top attribute set is selected.
Characteristic | Description |
---|---|
Attribute Set | Default |
Product Name | Champ Tee |
SKU | MS-Champ |
Price | 25.00 |
Tax Class | Taxable Goods |
Weight | 0.5 |
Categories | Men, Tops, Tees |
Visibility | Catalog, Search |
Color | Gray |
Description | The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10. |
A merchant typically provides the product name, SKU, price, weight, and description. The other characteristics are defined by the system.
Find the system-defined values
We’ll make several calls to find the values needed to create the product
Get the attribute set ID
The sample data provides multiple attribute sets, including Default, Top, and Bottom. To assign the Top attribute set to the product, we need to know the corresponding attribute_set_id
.
Use the following call to search for the attribute set named Top
.
Endpoint
GET /rest/<store_code>/V1/eav/attribute-sets/list? searchCriteria[filter_groups][0][filters][0][field]=attribute_set_name& searchCriteria[filter_groups][0][filters][0][value]=Default& searchCriteria[filter_groups][0][filters][0][condition_type]=eq |
Response
The attribute_set_id
for the Default attribute set is 2
.
{ "items": [ { "attribute_set_id": 2, "attribute_set_name": "Default", "sort_order": 0, "entity_type_id": 4 } ], "search_criteria": { "filter_groups": [ { "filters": [ { "field": "attribute_set_name", "value": "Default", "condition_type": "eq" } ] } ] }, "total_count": 1 } |
Get the list of attributes defined in an attribute searchCriteria
Use the GET V1/products/attribute-sets/:attributeSetId/attributes
call to return information about the attributes defined in the Top attribute set.
Endpoint
GET /rest/default/V1/products/attribute-sets/9/attributes
Response
The response contains almost 3,000 lines. The following table provides a summary of the attributes that are relevant in this tutorial.
Admin label | Selected value | Attribute ID | attribute_code | Attribute value |
---|---|---|---|---|
Tax Class | Taxable Goods | 132 | tax_class_id |
2 |
Visibility | Catalog, Search | 99 | visibility |
4 |
Color | Gray | 93 | color |
52 |
The attribute ID and value numbers might be different on your installation. Check the values carefully before using them in your calls.
Get the list of category values
You must assign the product to one or more categories to enable customers to find the product by browsing. We’ll assign the Champ Tee to the Men, Tops, and Tees categories.
Use the following call to search for all categories (id
is greater than or equal to 0
).
GET /rest/default/V1/categories? searchCriteria[filter_groups][0][filters][0][field]=id& searchCriteria[filter_groups][0][filters][0][value]=1& searchCriteria[filter_groups][0][filters][0][condition_type]=gte |
Note that women’s tops and tees have different ids than men’s tops and tees. The values for men’s clothing are:
- Men –
11
- Tops –
12
- Tees –
16
Step 2. Create the simple products
Although it’s not required, the simple product payload also includes stock_item
information. By default, the RCE store hides out-of-stock items, so adding stock will make the Champ Tee visible on the website.
Create the first simple product
Before you using this code sample, verify that the attribute values are the same in your installation. See above
Endpoint
POST /rest/default/V1/products
Payload
{ "product": { "sku": "MS-Champ", "name": "Champ Tee", "attribute_set_id": 2, "price": 25, "status": 1, "visibility": 4, "type_id": "simple", "weight": "0.5", "extension_attributes": { "category_links": [ { "position": 0, "category_id": "11" }, { "position": 1, "category_id": "12" }, { "position": 2, "category_id": "16" } ], "stock_item": { "qty": "10", "is_in_stock": true } }, "custom_attributes": [ { "attribute_code": "description", "value": "The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10." }, { "attribute_code": "tax_class_id", "value": "2" }, { "attribute_code": "color", "value": "52" } ] } } |
Response
{ "id": 2079, "sku": "MS-Champ", "name": "Champ Tee", "attribute_set_id": 2, "price": 25, "status": 1, "visibility": 4, "type_id": "simple", "created_at": "2017-11-29 20:40:07", "updated_at": "2017-11-29 20:40:07", "weight": 0.5, "extension_attributes": { "website_ids": [ 1 ], "category_links": [ { "position": 0, "category_id": "11" }, { "position": 1, "category_id": "12" }, { "position": 2, "category_id": "16" } ], "stock_item": { "item_id": 2079, "product_id": 2079, "stock_id": 1, "qty": 10, "is_in_stock": true, "is_qty_decimal": false, "show_default_notification_message": false, "use_config_min_qty": true, "min_qty": 0, "use_config_min_sale_qty": 1, "min_sale_qty": 1, "use_config_max_sale_qty": true, "max_sale_qty": 10000, "use_config_backorders": true, "backorders": 0, "use_config_notify_stock_qty": true, "notify_stock_qty": 1, "use_config_qty_increments": true, "qty_increments": 0, "use_config_enable_qty_inc": true, "enable_qty_increments": false, "use_config_manage_stock": true, "manage_stock": true, "low_stock_date": null, "is_decimal_divided": false, "stock_status_changed_auto": 0 } }, "product_links": [], "options": [], "media_gallery_entries": [], "tier_prices": [], "custom_attributes": [ { "attribute_code": "description", "value": "The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10." }, { "attribute_code": "color", "value": "52" }, { "attribute_code": "category_ids", "value": [ "11", "12", "16" ] }, { "attribute_code": "options_container", "value": "container2" }, { "attribute_code": "required_options", "value": "0" }, { "attribute_code": "has_options", "value": "0" }, { "attribute_code": "url_key", "value": "champ-tee-small" }, { "attribute_code": "tax_class_id", "value": "2" } ] } |
Create a configurable product tutorial
A configurable product is an item that requires the customer to choose one or more ‘options’ prior to purchase.
For example, when buying shoes, the customer needs to select what shoe size they want to buy. Many clothing items may well have both colour and size choices that have to be made by the customer.
Resources
https://rezolve.com/rceapidocs/swagger-products/
Step 1. Plan the product
To create a configurable product programmatically, you’ll need to know the following:
- The attribute names and values defined in the attribute set assigned to the configurable product.
- The categories numbers assigned to the configurable product.
- Which attributes to use as the configuration options.
Since this tutorial uses the sample data, we can take advantage of the options that the Top attribute set provides. This attribute set contains attributes that describe the fabric, sleeve length, and other characteristics that are specific to clothing. It also includes EAV attributes such as size and color, which are commonly available to all types of physical products.
The size of the t-shirt will be the configurable aspect of this product. Therefore, we’ll create a simple product for each size (Small, Medium, and Large).
Define product characteristics
The following table lists the general characteristics of men’s t-shirt we’re creating. These items are among those listed on the New Product page in Admin when the Top attribute set is selected.
Characteristic | Description |
---|---|
Attribute Set | Top |
Product Name | Champ Tee |
SKU | MS-Champ |
Price | 25.00 |
Tax Class | Taxable Goods |
Weight | 0.5 |
Categories | Men, Tops, Tees |
Visibility | Catalog, Search |
Material | LumaTech |
Pattern | Graphic Print |
Color | Gray |
Size | Configurable in small, medium, or large |
Description | The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10. |
A merchant typically provides the product name, SKU, price, weight, and description. The other characteristics are defined by the system.
Find the system-defined values
We’ll make several calls to find the values needed to create the product
Get the attribute set ID
The sample data provides multiple attribute sets, including Default, Top, and Bottom. To assign the Top attribute set to the product, we need to know the corresponding attribute_set_id
.
Use the following call to search for the attribute set named Top
.
Endpoint
GET /rest/<store_code>/V1/eav/attribute-sets/list? searchCriteria[filter_groups][0][filters][0][field]=attribute_set_name& searchCriteria[filter_groups][0][filters][0][value]=Top& searchCriteria[filter_groups][0][filters][0][condition_type]=eq |
Response
The attribute_set_id
for the Top attribute set is 9
.
{ "items": [ { "attribute_set_id": 9, "attribute_set_name": "Top", "sort_order": 0, "entity_type_id": 4 } ], "search_criteria": { "filter_groups": [ { "filters": [ { "field": "attribute_set_name", "value": "Top", "condition_type": "eq" } ] } ] }, "total_count": 1 } |
Get the list of attributes defined in an attribute searchCriteria
Use the GET V1/products/attribute-sets/:attributeSetId/attributes
call to return information about the attributes defined in the Top attribute set.
Endpoint
GET /rest/default/V1/products/attribute-sets/9/attributes
Response
The response contains almost 3,000 lines. The following table provides a summary of the attributes that are relevant in this tutorial.
Admin label | Selected value | Attribute ID | attribute_code | Attribute value |
---|---|---|---|---|
Tax Class | Taxable Goods | 132 | tax_class_id |
2 |
Visibility | Catalog, Search | 99 | visibility |
4 |
Material | LumaTech | 136 | material |
148 |
Pattern | Graphic Print | 152 | pattern |
196 |
Color | Gray | 93 | color |
52 |
Size | Not applicable | 141 | size |
168 (small), 169 (medium), 170 (large) |
The attribute ID and value numbers might be different on your installation. Check the values carefully before using them in your calls.
Get the list of category values
You must assign the product to one or more categories to enable customers to find the product by browsing. We’ll assign the Champ Tee to the Men, Tops, and Tees categories.
Use the following call to search for all categories (id
is greater than or equal to 0
).
GET /rest/default/V1/categories? searchCriteria[filter_groups][0][filters][0][field]=id& searchCriteria[filter_groups][0][filters][0][value]=1& searchCriteria[filter_groups][0][filters][0][condition_type]=gte |
Note that women’s tops and tees have different ids than men’s tops and tees. The values for men’s clothing are:
- Men –
11
- Tops –
12
- Tees –
16
Step 2. Create the configurable product
We have the information we need to create the Champ Tee configurable product.
The sample payload does not contain the price or the size. These attributes will be defined in the simple products.
The visibility
attribute is set to 4, meaning the product can be found by browsing or searching. This value will be changed for the simple products.
Before you using this code sample, verify that the attribute values are the same in your installation.
Endpoint
POST /rest/default/V1/products
Payload
{ "product": { "sku": "MS-Champ", "name": "Champ Tee", "attribute_set_id": 9, "status": 1, "visibility": 4, "type_id": "configurable", "weight": "0.5", "extension_attributes": { "category_links": [ { "position": 0, "category_id": "11" }, { "position": 1, "category_id": "12" }, { "position": 2, "category_id": "16" } ] }, "custom_attributes": [ { "attribute_code": "description", "value": "The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10." }, { "attribute_code": "tax_class_id", "value": "2" }, { "attribute_code": "material", "value": "148" }, { "attribute_code": "pattern", "value": "196" }, { "attribute_code": "color", "value": "52" } ] } } |
Response
{ "id": 2078, "sku": "MS-Champ", "name": "Champ Tee", "attribute_set_id": 9, "price": 0, "status": 1, "visibility": 4, "type_id": "configurable", "created_at": "2017-11-29 19:57:20", "updated_at": "2017-11-29 19:57:20", "weight": 0.5, "extension_attributes": { "website_ids": [ 1 ], "category_links": [ { "position": 0, "category_id": "11" }, { "position": 1, "category_id": "12" }, { "position": 2, "category_id": "16" } ], "stock_item": { "item_id": 2078, "product_id": 2078, "stock_id": 1, "qty": 0, "is_in_stock": false, "is_qty_decimal": false, "show_default_notification_message": false, "use_config_min_qty": true, "min_qty": 0, "use_config_min_sale_qty": 1, "min_sale_qty": 1, "use_config_max_sale_qty": true, "max_sale_qty": 10000, "use_config_backorders": true, "backorders": 0, "use_config_notify_stock_qty": true, "notify_stock_qty": 1, "use_config_qty_increments": true, "qty_increments": 0, "use_config_enable_qty_inc": true, "enable_qty_increments": false, "use_config_manage_stock": true, "manage_stock": true, "low_stock_date": null, "is_decimal_divided": false, "stock_status_changed_auto": 0 }, "configurable_product_options": [], "configurable_product_links": [] }, "product_links": [], "options": [], "media_gallery_entries": [], "tier_prices": [], "custom_attributes": [ { "attribute_code": "description", "value": "The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10." }, { "attribute_code": "color", "value": "52" }, { "attribute_code": "category_ids", "value": [ "11", "12", "16" ] }, { "attribute_code": "options_container", "value": "container2" }, { "attribute_code": "required_options", "value": "0" }, { "attribute_code": "has_options", "value": "0" }, { "attribute_code": "url_key", "value": "champ-tee" }, { "attribute_code": "tax_class_id", "value": "2" }, { "attribute_code": "material", "value": "148" }, { "attribute_code": "size", "value": "91" }, { "attribute_code": "pattern", "value": "196" } ] } |
Step 3. Create the simple products
The payloads for creating a simple product and a configurable product are identical, with the following exceptions:
- The simple product
sku
appends the configurable option (the size in this tutorial) to the configurable productsku
. - The
name
indicates the size. - The
type_id
is set tosimple
. - The
visibility
is set to1
, indicating the simple product should not be displayed on the store. - The
price
andsize
attributes are specified.
Although it’s not required, the simple product payload also includes stock_item
information. By default, the RCE store hides out-of-stock items, so adding stock will make the Champ Tee visible on the website.
Create the first simple product
Before you using this code sample, verify that the attribute values are the same in your installation.
Endpoint
POST /rest/default/V1/products
Payload
{ "product": { "sku": "MS-Champ-S", "name": "Champ Tee Small", "attribute_set_id": 9, "price": 25, "status": 1, "visibility": 1, "type_id": "simple", "weight": "0.5", "extension_attributes": { "category_links": [ { "position": 0, "category_id": "11" }, { "position": 1, "category_id": "12" }, { "position": 2, "category_id": "16" } ], "stock_item": { "qty": "10", "is_in_stock": true } }, "custom_attributes": [ { "attribute_code": "description", "value": "The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10." }, { "attribute_code": "tax_class_id", "value": "2" }, { "attribute_code": "material", "value": "148" }, { "attribute_code": "pattern", "value": "196" }, { "attribute_code": "color", "value": "52" }, { "attribute_code": "size", "value": "168" } ] } } |
Response
{ "id": 2079, "sku": "MS-Champ-S", "name": "Champ Tee Small", "attribute_set_id": 9, "price": 25, "status": 1, "visibility": 1, "type_id": "simple", "created_at": "2017-11-29 20:40:07", "updated_at": "2017-11-29 20:40:07", "weight": 0.5, "extension_attributes": { "website_ids": [ 1 ], "category_links": [ { "position": 0, "category_id": "11" }, { "position": 1, "category_id": "12" }, { "position": 2, "category_id": "16" } ], "stock_item": { "item_id": 2079, "product_id": 2079, "stock_id": 1, "qty": 10, "is_in_stock": true, "is_qty_decimal": false, "show_default_notification_message": false, "use_config_min_qty": true, "min_qty": 0, "use_config_min_sale_qty": 1, "min_sale_qty": 1, "use_config_max_sale_qty": true, "max_sale_qty": 10000, "use_config_backorders": true, "backorders": 0, "use_config_notify_stock_qty": true, "notify_stock_qty": 1, "use_config_qty_increments": true, "qty_increments": 0, "use_config_enable_qty_inc": true, "enable_qty_increments": false, "use_config_manage_stock": true, "manage_stock": true, "low_stock_date": null, "is_decimal_divided": false, "stock_status_changed_auto": 0 } }, "product_links": [], "options": [], "media_gallery_entries": [], "tier_prices": [], "custom_attributes": [ { "attribute_code": "description", "value": "The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10." }, { "attribute_code": "color", "value": "52" }, { "attribute_code": "category_ids", "value": [ "11", "12", "16" ] }, { "attribute_code": "options_container", "value": "container2" }, { "attribute_code": "required_options", "value": "0" }, { "attribute_code": "has_options", "value": "0" }, { "attribute_code": "url_key", "value": "champ-tee-small" }, { "attribute_code": "tax_class_id", "value": "2" }, { "attribute_code": "material", "value": "148" }, { "attribute_code": "size", "value": "168" }, { "attribute_code": "pattern", "value": "196" } ] } |
Create the other simple products
Repeat the call with the following changes to the payload:
Attribute | Medium Value | Large Value |
---|---|---|
sku |
MS-Champ-M | MS-Champ-L |
name |
Champ Tee Medium | Champ Tee Large |
size |
169 | 170 |
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 /rest/default/V1/configurable-products/MS-Champ/options
Payload
{ "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 /rest/default/V1/configurable-products/MS-Champ/child
Payload
{ "childSku": "MS-Champ-S" } |
Response
true
Verify this step
- Log in to the RCE and select Catalog > Products. Click on the Champ Tee configurable product and expand the Configurations section.
- Call
GET /V1/products/MS-Champ
. The response includes theconfigurable_product_options
andconfigurable_product_links
arrays.
... "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 ] }, ... |
Step 5. Create the personalization option
Let’s add a text box to the product page that allows the customer to add his name (up to 15 characters) to the back of shirt.
The product_sku
is the sku
of the configurable product. The sku
specified in the payload is a string that is appended to the product_sku
when a customer decides to purchase this option. Likewise, the price
supplied in the payload is added to the configurable product price.
Endpoint
POST /rest/default/V1/products/options
Payload
{ "option": { "product_sku": "MS-Champ", "title": "Add Your Name (Max 15 Characters)", "type": "field", "sort_order": 1, "is_require": false, "price": 10, "price_type": "fixed", "sku": "Personalized", "max_characters": 15 } } |
Response
{ "product_sku": "MS-Champ", "option_id": 7, "title": "Add Your Name (Max 15 Characters)", "type": "field", "sort_order": 1, "is_require": false, "price": 10, "price_type": "fixed", "sku": "Personalized", "max_characters": 15 } |
Single SKU update
The following call asynchronously changes the price of the product that has a sku of sku1
PUT <host>/rest/<store_code>/async/V1/products/sku1
Request Data
{
"product": {
"price": 29
}
}
Response
{
"bulk_uuid": "fbfca270-7a90-4c4e-9f32-d6cf3728cdc7",
"request_items": [
{
"id": 0,
"data_hash": "9c1bd4bfd8defcc856ddf129cc01d172625d139d5f7dcf53b6cb09a0e9a843a3",
"status": "accepted"
}
],
"errors": false
}
Bulk SKU update
Updating Stock and Price can also be done using the BULK update APIs
Get stock item for each product
Product 1
GET <host>/rest/V1/stockItems/test1%22
Product 1 Response
{
"item_id":1,
"product_id":1,
"stock_id":1,
"qty":1,
"is_in_stock":true,
"is_qty_decimal":false,
"show_default_notification_message":false,
"use_config_min_qty":true,
"min_qty":0,
"use_config_min_sale_qty":1,
"min_sale_qty":1,
"use_config_max_sale_qty":true,
"max_sale_qty":20,
"use_config_backorders":true,
"backorders":0,
"use_config_notify_stock_qty":true,
"notify_stock_qty":1,
"use_config_qty_increments":true,
"qty_increments":0,
"use_config_enable_qty_inc":true,
"enable_qty_increments":false,
"use_config_manage_stock":true,
"manage_stock":true,
"low_stock_date":null,
"is_decimal_divided":false,
"stock_status_changed_auto":0,
"extension_attributes":[
]
}
Product 2
GET <host>/rest/V1/stockItems/test2
Product 2 Response
{
"item_id":2,
"product_id":2,
"stock_id":1,
"qty":1,
"is_in_stock":true,
"is_qty_decimal":false,
"show_default_notification_message":false,
"use_config_min_qty":true,
"min_qty":0,
"use_config_min_sale_qty":1,
"min_sale_qty":1,
"use_config_max_sale_qty":true,
"max_sale_qty":20,
"use_config_backorders":true,
"backorders":0,
"use_config_notify_stock_qty":true,
"notify_stock_qty":1,
"use_config_qty_increments":true,
"qty_increments":0,
"use_config_enable_qty_inc":true,
"enable_qty_increments":false,
"use_config_manage_stock":true,
"manage_stock":true,
"low_stock_date":null,
"is_decimal_divided":false,
"stock_status_changed_auto":0,
"extension_attributes":[
]
}
Update stock by request
PUT <host>/rest/async/bulk/V1/products/bySku
Payload
[
{
"product":{
"sku":"test1",
"name":"Test1",
"attribute_set_id":4,
"status":1,
"visibility":4,
"price":30,
"type_id":"simple",
"extension_attributes":{
"stock_item":{
"item_id":1,
"product_id":1,
"stock_id":1,
"qty":20,
"is_in_stock":true
}
},
"custom_attributes":[
]
}
},
{
"product":{
"sku":"test2",
"name":"Test2",
"attribute_set_id":4,
"status":1,
"visibility":4,
"price":50,
"type_id":"simple",
"extension_attributes":{
"stock_item":{
"item_id":2,
"product_id":2,
"stock_id":1,
"qty":70,
"is_in_stock":true
}
},
"custom_attributes":[
]
}
}
]