Creates a new variant for a product. Set the variant’s attributes and options, the parts it’s made of, and optionally its pricing. The response returns the new variant_id.
Before you begin#
- The API token needs
ProductVariant_Insert, either assigned directly under Functions or through a group. See Create an API token. - Requests must be signed if the token requires it. See Make a signed request with HMAC.
- You need the product’s
Product_ID,Edit_Product,Product_CodeorProduct_SKU.
Example requests#
Create a variant#
Creates a variant with two attribute/option pairs, two parts and specific pricing.
{
"Store_Code": "{{Store_Code}}",
"Miva_Request_Timestamp": "{{$timestamp}}",
"Function": "ProductVariant_Insert",
"Product_ID": "{{Product_ID}}",
"Attributes": [
{
"attr_code": "ATTRIBUTE_CODE",
"option_code": "OPTION_CODE"
},
{
"attr_code": "ATTRIBUTE_CODE",
"option_code": "OPTION_CODE"
}
],
"Parts": [
{
"part_code": "PART_PRODUCT_CODE",
"quantity": 1
},
{
"part_code": "PART_PRODUCT_CODE",
"quantity": 1
}
],
"Pricing": {
"method": "specific",
"price": 10,
"cost": 10,
"weight": 10
}
}
method takes "master" or 0, "specific" or 1, or "sum" or 2.
Request parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
product_idEdit_ProductProduct_CodeProduct_SKU |
Number String String String |
ID Number of product Product code string Product code string Product SKU string |
|
attribute_ids |
Number | The attribute id of the product | |
AttributeTemplateAttribute_IDs |
Number | The attribute template ids of the product attribute | |
option_ids |
Number | The option id numbers of the product | |
part_ids |
Number | The id numbers of the product parts | |
quantities |
Number | The part quantities for the product variant | |
attributes |
Object | Object containing the attribute codes and options | |
attr_code |
String | String of attribute code assigned to variant | |
option_code |
String | String of option code assigned to variant | |
parts |
Object | Object containing the part codes and quantities | |
part_code |
String | String of part product code assigned to variant | |
quantity |
Number | Number of parts assigned to variant | |
pricing |
Object | Object containing the pricing settings |
attributes Object#
| Parameter | Type | Description |
|---|---|---|
attr_id |
Number | Attribute ID. Use attr_id or attr_code, not both. |
attr_code |
String | Attribute code |
attmpat_id |
Number | Attribute template attribute ID. Use attmpat_id or attmpat_code, not both. |
attmpat_code |
String | Attribute template attribute code |
option_id |
Number | Option ID. Use option_id or option_code, not both. |
option_code |
String | Option code |
When Attributes is present, Attribute_IDs, AttributeTemplateAttribute_IDs and Option_IDs are ignored.
parts Object#
| Parameter | Type | Description |
|---|---|---|
part_id |
Number | Part ID. Use part_id or part_code, not both. |
part_code |
String | Product code of the part |
quantity |
Number | Quantity of Part. Required. |
When Parts is present, Part_IDs and Quantities are ignored.
pricing Object#
| Parameter | Type | Description |
|---|---|---|
method |
String / Number | “master”/0 “specific”/1 “sum”/2 |
price |
Number | Number containing the price of the variant |
cost |
Number | Number containing the cost of the variant |
weight |
Number | Number containing the weight of the variant |
Note
When the Pricing object exists, only the method member should be required, with the other 3 members all optional. Price, cost, and weight should all have default values of 0.00.
Example response#
{
"success": 1,
"data": {
"product_id": 1737,
"variant_id": 38,
"option_id_36_0": 59,
"option_code_36_0": "OPTION_CODE",
"attributes": [
{
"attr_id": 36,
"attr_code": "ATTRIBUTE_CODE",
"attmpat_id": 0,
"option_id": 59,
"option_code": "OPTION_CODE"
}
],
"parts": [
{
"product_id": 1793,
"product_code": "PART_PRODUCT_CODE",
"product_sku": "",
"product_name": "PART_PRODCUCT_NAME",
"quantity": 1
}
]
}
}
Response parameters#
| Parameter | Type | Description |
|---|---|---|
success |
Boolean | Boolean value indicating if the API request was successful |
product_id |
Number | The product id for the variant |
variant_id |
Number | The new variant id |
Related functions#
| Function | Use it to |
|---|---|
ProductVariant_Update |
Change a product variant |
ProductVariantPricing_Update |
Change a variant’s pricing |
ProductVariantList_Delete |
Delete product variants |
ProductVariantList_Load_Query |
Load a product’s variants |
AttributeAndOptionList_Load_Product |
Load a product’s attributes and options |
Try in Postman#
In the Miva: JSON API: Authenticated collection, open Products > ProductVariant_Insert. See Set Up Postman.