Hyvä Theme is Now Open Source: What This Means for Magento Community - Mageplaza
Hyvä is now Open Source and free. Discover what changed, what remains commercial, how it impacts the Magento ecosystem, and how to maximize its full potential.
Vinh Jacker | 03-17-2025
Efficiency and precision are key to managing an online store in eCommerce. Magento 2, one of the leading eCommerce platforms, provides robust REST APIs that empower developers to create and update products programmatically. Whether you’re launching a new catalog, syncing inventory, or fine-tuning product details, the REST API is your gateway to seamless automation.
Imagine this: with just a few API calls, you can transform how you manage product data—eliminating manual entry, reducing errors, and saving precious time. In this guide, we’ll walk you through how to create and update products effortlessly using REST API in Magento 2. Ready to supercharge your product management? Let’s dive in!
To authenticate your API requests, you need to generate an admin access token. If you’re unsure how to obtain this token, please check our Get Admin Token Magento 2 API guide for detailed instructions.
Before making API calls to update products or perform other tasks in Magento 2, ensure the following requirements are met:
Note:
sku attaches the configurable option to the configurable product sku.name shows the size.stock_item information. By default, out-of-stock items are hidden, so adding stock will make the product visible on the website.Assuming that we need to create a small Dime t-shirt as a single product in Magento 2. The following table displays the attributes of the men t-shirt we are creating:
| Characteristic | Description |
|---|---|
| Attribute Set | Top |
| Product Name | Dime Tee Small |
| SKU | MS-Dime-S |
| Price | 30 |
| Tax Class | Taxable Goods |
| Weight | 0.6 |
| Categories | Men, Tops, Tees |
| Visibility | Not display on the store |
| Material | LumaTech |
| Pattern | Graphic Print |
| Color | Gray |
| Size | Small |
| Description | The Dime Tee is soft, comfortable and durable. You will love the way you look in this tailored tee shirt. |
The online store typically gives the product name, SKU, price, weight, and description. The system defines other attributes.
To find the values needed to create the product, we have to make several calls.
Please use the below code sample to create the first simple product.
POST <host>/rest/default/V1/products
{
"product": {
"sku": "MS-Dime-S",
"name": "Dime Tee Small",
"attribute_set_id": 9,
"price": 25,
"status": 1,
"visibility": 1,
"type_id": "simple",
"weight": "0.6",
"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 Dime Tee is soft, comfortable and durable. You will love the way you look in this tailored tee shirt."
},
{
"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"
}
]
}
}
{
"id": 2079,
"sku": "MS-Dime-S",
"name": "Dime 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.6,
"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 Dime Tee is soft, comfortable and durable. You will love the way you look in this tailored tee shirt."
},
{
"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"
}
]
}
If you want to create other simple products (for example Dime Tee in medium or large size), repeat the call with the following changes to the payload:
| Attribute | Medium Value | Large Value |
|---|---|---|
| sku | MS-Dime-M | MS-Dime-L |
| name | Dime Tee Medium | Dime Tee Large |
| size | 169 | 170 |
Catalog > Products. Now you will see the products on the grid.Updating a product in Magento 2 can be done efficiently via the API. Below are the steps and details for achieving this:
API Endpoint:
Request Method: PUT
Request Body:
{
"product": {
"price": 20000,
"custom_attributes": [
{
"attribute_code": "color",
"value": "47"
}
]
}
}