Product Variant API
Use the REST API to interact with EverShop product variant.
Create a variant group
Use this endpoint to create a variant group.
Request Schema (application/json)
Field Name | Field Type | Required |
---|---|---|
attribute_codes | array of string | Yes |
attribute_group_id | integer or string | No |
POST/api/variantGroups
- cURL
- JavaScript
curl
-H "Accept: application/json"
-H "Cookie: asid=<your admin cookie>"
https://<your domain>/api/variantGroups
fetch('https://<your domain>/api/variantGroups', {
headers: {
'Accept': 'application/json',
'Cookie': 'asid=<your admin cookie>'
}
})
.then(response => response.json())
.then(data => {
if(data.error) {
// Handle the error
} else {
// Handle the data
}
})
.catch(error => {
// Handle the error
});
Sample Of Response
{
"data": {
"variant_group_id": 8,
"uuid": "99a7b39ca63211edb46b60d819134f39",
"attribute_group_id": 1,
"attribute_one": 4,
"attribute_two": 2,
"attribute_three": 3,
"attribute_four": 5,
"attribute_five": 6
}
}
Add variant item
Use this endpoint to add a product to a variant group.
Request Schema (application/json)
Field Name | Field Type | Required |
---|---|---|
product_id | string | Yes |
POST/api/variantGroups/{id}/items
- cURL
- JavaScript
curl
-H "Accept: application/json"
-H "Cookie: asid=<your admin cookie>"
https://<your domain>/api/variantGroups/{id}/items
fetch('https://<your domain>/api/variantGroups/{id}/items', {
headers: {
'Accept': 'application/json',
'Cookie': 'asid=<your admin cookie>'
}
})
.then(response => response.json())
.then(data => {
if(data.error) {
// Handle the error
} else {
// Handle the data
}
})
.catch(error => {
// Handle the error
});
Sample Of Response
{
"data": {
"id": "r57hfgh5656",
"attributes": [
{
"attribute_id": 2,
"attribute_code": "color",
"option_id": 5
},
{
"attribute_id": 3,
"attribute_code": "size",
"option_id": 6
}
],
"product": {
"product_id": 281,
"uuid": "99a7b39ca63211edb46b60d819134f39",
"variant_group_id": 2,
"visibility": 1,
"group_id": 4,
"image": null,
"sku": "skuUpdated",
"price": 45,
"qty": 123,
"weight": 17,
"manage_stock": 1,
"stock_availability": 1,
"tax_class": null,
"status": 1,
"created_at": "2023-02-07 00:01:46",
"updated_at": "2023-02-07 00:01:46"
}
}
}