Requires
write_product
access scope. More access scope
The Create Variant API allows users to add a new product variant to an existing product by specifying details such as options, pricing, inventory, and wholesale information. This operation is used to expand a product’s available options by creating additional variants with unique attributes.This API is especially useful for:
1.Adding new variants to existing products with different options like size, color, or style.
2.Managing inventory and pricing for individual product variants.
3.Customizing product variants for wholesale or retail purposes.
Note: The operation is scoped to a specific shop, identified by its unique domain prefix (shopdomain), ensuring all updates are applied to the correct store.
Public Request Parameters
Parameter Name | Type | Required | Parameter Location | Parameter Value | Description |
---|---|---|---|---|---|
Access-Token | String | Yes | Header | Bx-_5aV eXNwl-4AB98s5xLV yg0fNzGf MuTpqtlBA | Used to authenticate API requests. Obtain an access token from the Access Token Guide. Pass it in the Authorization header for every request. |
Content-Type | String | Yes | Header | application /json | Indicates the media type of the request body. It tells the server how to parse the request and the client how to interpret the response. For more details, visit Content-Type. |
Public Response Parameters
Parameter Name | Type | Mandatory | Parameter Location | Example Value | Description |
---|---|---|---|---|---|
error | String | No | Response Body | { "error": "store is not active" } | Indicates an error encountered during the process. This field typically appears when the Access Token is missing or invalid. Example: { "error": "store is not active" } . |
errors | Array | No | Response Body | { "errors"["No Context"] } | A list of errors that occurred during the request processing. Example: { "errors": [ "No Context" ] } . |
Request-Id | String | Yes | Header | Bx-_5aV eXNwl-4AB98s5xLV yg0fNzGf MuTpqtlBA | A unique identifier for each request. It helps in identifying and debugging specific requests. |
Error and Errors Clarification:
Added explanation that the error and errors fields are currently dependent on the API implementation, with plans for future unification.
Request Parameters
Path Parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
product_id | string | Yes | 9fb9f3c6-2300-42c1-8593-d9008d7cfc09 | The unique identifier for the product. |
Body Parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
product_id | string | Yes | a1a88be0-a1d4-47e4-a2f2-ba6e131cf447 | Product's unique identifier. |
variant.option1 | string | No | Red | The first option for the variant (e.g., color, size). |
variant.option2 | string | No | Large | The second option for the variant. |
variant.option3 | string | No | Cotton | The third option for the variant. |
variant.compare_at_price | string | No | 29.99 | The original price of the variant before any discounts. |
variant.image_id | string | No | 8ef098c5-5a08-44b4-b5fb-89214bb507dc | The ID of the image associated with the variant. |
variant.price | string | Yes | 19.99 | The current price of the variant. |
variant.position | integer | Yes | 1 | The position of the variant in the list of product variants. |
variant.sku | string | No | T-M-L-red | Stock Keeping Unit (SKU) for the variant. |
variant.barcode | string | No | 6929000212340 | The barcode associated with the variant. |
variant.note | string | No | Limited Edition | Notes or additional information about the variant. |
variant.inventory_quantity | integer | No | 50 | The number of items available in inventory for the variant. |
variant.weight | string | No | 1.2 | The weight of the variant. |
variant.weight_unit | string | No | kg | The unit of measurement for the weight (e.g., kg , lb ). |
variant.cost_price | string | No | 15.00 | The cost price of the variant. |
variant.wholesale_price | array | No | Array of wholesale price | |
variant.wholesale_price.price | string | No | 17.99 | Wholesale price for the variant. |
variant.wholesale_price.min_quantity | integer | No | 10 | Minimum quantity required to avail the wholesale price. |
Response Explanation
Successful Response
Field | Type | Example | Description |
---|---|---|---|
variant.id | string | 1b735278-62c7-41ad-9976-b1b63a90590d | Unique identifier for the variant. |
variant.product_id | string | 636a07da-39eb-4829-bde9-b65fae1c28b0 | Unique identifier for the associated product. |
variant.image_id | string | 91d032e7-bbc8-47e4-8668-9ba6fe714de6 | Unique identifier for the associated image. |
variant.created_at | string (date) | 2024-04-15T02:00:57Z | Timestamp indicating when the variant was created. |
variant.updated_at | string (date) | 2024-04-15T02:00:57Z | Timestamp indicating when the variant was last updated. |
variant.title | string | S-red | Title of the variant. |
variant.option1 | string | S | First option value for the variant (e.g., size). |
variant.option2 | string | red | Second option value for the variant (e.g., color). |
variant.option3 | string | "" | Third option value for the variant, if applicable. |
variant.image | object | Image Object | |
variant.image.src | string | //cdn.shoplazza.com/efd33b921cacd5311a32dd03a9bc8740.png | URL of the image associated with the variant. |
variant.image.width | integer | 1588 | Width of the variant image in pixels. |
variant.image.height | integer | 2246 | Height of the variant image in pixels. |
variant.image.path | string | efd33b921cacd5311a32dd03a9bc8740.png | File path of the variant image. |
variant.image.alt | string | "" | Alternative text for the variant image. |
variant.position | integer | 1 | Position of the variant in the product's variant list. |
variant.compare_at_price | string | 100.00 | Original price of the variant before discounts. |
variant.price | string | 100.00 | Current price of the variant. |
variant.sku | string | S-RED | Stock Keeping Unit (SKU) for the variant. |
variant.barcode | string | 123 | Barcode associated with the variant. |
variant.note | string | s-red | Notes or additional information about the variant. |
variant.inventory_quantity | integer | 10 | Number of items available in inventory for the variant. |
variant.weight | string | 0.10 | Weight of the variant. |
variant.weight_unit | string | kg | Unit of measurement for the weight (e.g., kg, lb). |
variant.cost_price | string | 11.00 | Cost price of the variant. |
variant.wholesale_price | object | wholesale price object | |
variant.wholesale_price.price | string | 100.00 | Wholesale price for the variant. |
variant.wholesale_price.min_quantity | integer | 1 | Minimum quantity required to avail the wholesale price. |
variant.extend | object | extend object | Additional details about the variant's dimensions or origin. |
variant.extend.length | number | 10 | length |
variant.extend.width | number | 10 | width |
variant.extend.height | number | 10 | height |
variant.extend.dimension_unit | string | "in" | dimension_unit |
variant.extend.origin_country_code | string | "AS" | Country of origin code of the product. |
variant.extend.hs_code | string | "6211439" | HS codes are the international standard for commodity classification, and Shoplazza can automatically generate HS codes based on commodity information. |
Error Response
Error responses in the API can be represented using two different fields: errors
and error
. Both fields provide details about issues encountered during request processing. Below is an explanation of the fields with their respective examples and descriptions.
Field | Type | Example | Description |
---|---|---|---|
errors | Array | ["No Context"] | A list of errors encountered during the request processing. |
Field | Type | Example | Description |
---|---|---|---|
error | Array | "store is not active" | Indicates an error encountered during the process. |
Request Examples
curl --request POST \
--url https://shopdomain.myshoplaza.com/openapi/2022-01/products/product_id/variants \
--header 'accept: application/json' \
--header 'access-token: WPMSdB6M8Cpum4X1GoMYOKZpiESd8d2x7dZW8d79ZeQ' \
--header 'content-type: application/json' \
--data '{
"variant": {
"option1": "S",
"option2": "red",
"option3": "",
"compare_at_price": "100.00",
"image_id": "91d032e7-bbc8-47e4-8668-9ba6fe714de6",
"price": "90.00",
"position": 1,
"sku": "S-RED",
"barcode": "123456789",
"note": "This is a sample variant",
"inventory_quantity": 50,
"weight": "0.50",
"weight_unit": "kg",
"cost_price": "50.00",
"wholesale_price": [
{
"price": "85.00",
"min_quantity": 10
},
{
"price": "80.00",
"min_quantity": 50
}
]
}
}'
Success Response Example
{
"variant": {
"id": "1b735278-62c7-41ad-9976-b1b63a90590d",
"product_id": "636a07da-39eb-4829-bde9-b65fae1c28b0",
"image_id": "91d032e7-bbc8-47e4-8668-9ba6fe714de6",
"created_at": "2024-04-15T02:00:57Z",
"updated_at": "2024-04-15T02:00:57Z",
"title": "S-red",
"option1": "S",
"option2": "red",
"option3": "",
"image": {
"src": "//cdn.shoplazza.com/efd33b921cacd5311a32dd03a9bc8740.png",
"width": 1588,
"height": 2246,
"path": "efd33b921cacd5311a32dd03a9bc8740.png",
"alt": ""
},
"position": 1,
"compare_at_price": "100.00",
"price": "100.00",
"sku": "S-RED",
"barcode": "123",
"note": "s-red",
"inventory_quantity": 10,
"weight": "0.10",
"weight_unit": "kg",
"cost_price": "11.00",
"wholesale_price": [
{
"price": "100.00",
"min_quantity": 1
}
],
"extend": null
}
}
Error Response Example
{
"errors": [
"productId has an invalid UUID"
]
}
{
"error": "store is not active"
}
Error Details
Status Code | Message | Possible Reason | Example Response |
---|---|---|---|
400 | Bad Request | Invalid input format or request structure (e.g., missing required fields or incorrect data types). | Bad Request |
Unauthorized | The request is missing valid authentication credentials or the credentials provided are invalid. | Unauthorized | |
404 | Product Not Found | The product ID provided in the request does not exist. | { "errors": ["Product not found"] } |
422 | Failed Validation | One or more fields failed validation checks. | { "errors": [ "Variant price must be entered."]} |
Invalid or empty id | missing required id or id with incorrect UUID types | { "errors": [ "Id is not an invalid UUID"]} | |
At least a single variant is included in the product | Cannot create additional variants because the product is set to have only a default variant (has_only_default_variant = true). | { "errors": [ "At least a single variant is included in the product." ] } |