> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # UpdateVariants # Package: catalogV1 # Namespace: CatalogWriteApi # Method link: https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/update-product-variants.md ## Permission Scopes: Manage Products: SCOPE.DC-STORES.MANAGE-PRODUCTS ## Introduction Updates variants of a specified product. --- ## REST API ### Schema ``` Method: updateVariants Description: Updates variants of a specified product. URL: https://www.wixapis.com/stores/v1/products/{id}/variants Method: PATCH Method parameters: param name: variants | type: array | description: Variant info to update. - name: choices | type: object | description: The specific choices available or chosen from within a selection (e.g., choosing the red Selection triggers the red Choice). You may specify all the relevant choices for a specific variant, or only some of the options, which will return all corresponding variants (Not relevant when passing variant GUIDs) - name: variantIds | type: array | description: List of variant GUIDs (Not relevant when passing choices) - name: price | type: number | description: Variant price - name: cost | type: number | description: Variant cost of goods - name: weight | type: number | description: Variant weight - name: sku | type: string | description: Variant SKU (stock keeping unit) - name: visible | type: boolean | description: Whether the variant is visible to customers - name: productDimensions | type: Dimensions | description: Product dimensions (length, width, height of the physical product) - name: length | type: string | description: Length. Measurement unit is handled at the system level (metric/imperial). - name: width | type: string | description: Width. Measurement unit is handled at the system level (metric/imperial). - name: height | type: string | description: Height. Measurement unit is handled at the system level (metric/imperial). - name: unit | type: DimensionsUnit | description: Unit of measurement for dimensions (length, width, height). - enum: - UNKNOWN_DIMENSIONS_UNIT: - MM: Millimeters. - CM: Centimeters. - M: Meters. - IN: Inches. - FT: Feet. - YD: Yards. - name: packageDimensions | type: Dimensions | description: Package dimensions (length, width, height of the shipping package) Return type: UpdateVariantsResponse - name: variants | type: array | description: List of the product's variants. - name: id | type: string | description: Requested Variant GUID - name: choices | type: object | description: Specific choices within a selection, as option-choice key-value pairs - name: variant | type: VariantDataWithNoStock | description: - name: priceData | type: PriceData | description: Variant price. - name: currency | type: string | description: Product price currency - name: price | type: number | description: Product price - name: discountedPrice | type: number | description: Discounted product price (if no discounted price is set, the product price is returned) - name: formatted | type: FormattedPrice | description: The product price and discounted price, formatted with the currency - name: price | type: string | description: Product price formatted with the currency - name: discountedPrice | type: string | description: Discounted product price formatted with the currency (if no discounted price is set, the product formatted price is returned) - name: pricePerUnit | type: string | description: Price per unit - name: pricePerUnit | type: number | description: Price per unit - name: convertedPriceData | type: PriceData | description: Variant price data, converted to currency requested in header. - name: costAndProfitData | type: CostAndProfitData | description: Cost and profit data. - name: itemCost | type: number | description: Item cost. - name: formattedItemCost | type: string | description: Item cost formatted with currency symbol. - name: profit | type: number | description: Profit. Calculated by reducing `cost` from `discounted_price`. - name: formattedProfit | type: string | description: Profit formatted with currency symbol. - name: profitMargin | type: number | description: Profit Margin. Calculated by dividing `profit` by `discounted_price`. The result is rounded to 4 decimal places. - name: weight | type: number | description: Variant weight. - name: sku | type: string | description: Variant SKU (stock keeping unit). - name: visible | type: boolean | description: Whether the variant is visible to customers. - name: productDimensions | type: Dimensions | description: Product dimensions (length, width, height of the physical product). - name: length | type: string | description: Length. Measurement unit is handled at the system level (metric/imperial). - name: width | type: string | description: Width. Measurement unit is handled at the system level (metric/imperial). - name: height | type: string | description: Height. Measurement unit is handled at the system level (metric/imperial). - name: unit | type: DimensionsUnit | description: Unit of measurement for dimensions (length, width, height). - enum: - UNKNOWN_DIMENSIONS_UNIT: - MM: Millimeters. - CM: Centimeters. - M: Meters. - IN: Inches. - FT: Feet. - YD: Yards. - name: packageDimensions | type: Dimensions | description: Package dimensions (length, width, height of the shipping package). - name: stock | type: VariantStock | description: Variant inventory status. - name: trackQuantity | type: boolean | description: Whether inventory is being tracked. - name: quantity | type: integer | description: Quantity currently left in inventory. - name: inStock | type: boolean | description: Whether the product is currently in stock (relevant only when tracking manually). ``` ### Examples ### UpdateVariants ```curl ~~~cURL curl -X PATCH \ 'https://www.wixapis.com/stores/v1/products/1044e7e4-37d1-0705-c5b3-623baae212fd/variants' \ --data-binary '{ "variants": [ { "choices": { "Size": 'S', "Color": 'Blue' }, "price": 100 } ] }' \ -H 'Content-Type: application/json' \ -H 'Authorization: ' ~~~ ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.catalogV1.CatalogWriteApi.updateVariants(_id, variants) Description: Updates variants of a specified product. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: _id, variants Method parameters: param name: _id | type: string | description: GUID of the product with managed variants. | required: true param name: variants | type: array | description: Variant info to update. | required: true - name: choices | type: object | description: The specific choices available or chosen from within a selection (e.g., choosing the red Selection triggers the red Choice). You may specify all the relevant choices for a specific variant, or only some of the options, which will return all corresponding variants (Not relevant when passing variant GUIDs) - name: variantIds | type: array | description: List of variant GUIDs (Not relevant when passing choices) - name: price | type: number | description: Variant price - name: cost | type: number | description: Variant cost of goods - name: weight | type: number | description: Variant weight - name: sku | type: string | description: Variant SKU (stock keeping unit) - name: visible | type: boolean | description: Whether the variant is visible to customers - name: productDimensions | type: Dimensions | description: Product dimensions (length, width, height of the physical product) - name: length | type: string | description: Length. Measurement unit is handled at the system level (metric/imperial). - name: width | type: string | description: Width. Measurement unit is handled at the system level (metric/imperial). - name: height | type: string | description: Height. Measurement unit is handled at the system level (metric/imperial). - name: unit | type: DimensionsUnit | description: Unit of measurement for dimensions (length, width, height). - enum: - UNKNOWN_DIMENSIONS_UNIT: - MM: Millimeters. - CM: Centimeters. - M: Meters. - IN: Inches. - FT: Feet. - YD: Yards. - name: packageDimensions | type: Dimensions | description: Package dimensions (length, width, height of the shipping package) Return type: PROMISE - name: variants | type: array | description: List of the product's variants. - name: _id | type: string | description: Requested Variant GUID - name: choices | type: object | description: Specific choices within a selection, as option-choice key-value pairs - name: variant | type: VariantDataWithNoStock | description: - name: priceData | type: PriceData | description: Variant price. - name: currency | type: string | description: Product price currency - name: price | type: number | description: Product price - name: discountedPrice | type: number | description: Discounted product price (if no discounted price is set, the product price is returned) - name: formatted | type: FormattedPrice | description: The product price and discounted price, formatted with the currency - name: price | type: string | description: Product price formatted with the currency - name: discountedPrice | type: string | description: Discounted product price formatted with the currency (if no discounted price is set, the product formatted price is returned) - name: pricePerUnit | type: string | description: Price per unit - name: pricePerUnit | type: number | description: Price per unit - name: convertedPriceData | type: PriceData | description: Variant price data, converted to currency requested in header. - name: costAndProfitData | type: CostAndProfitData | description: Cost and profit data. - name: itemCost | type: number | description: Item cost. - name: formattedItemCost | type: string | description: Item cost formatted with currency symbol. - name: profit | type: number | description: Profit. Calculated by reducing `cost` from `discounted_price`. - name: formattedProfit | type: string | description: Profit formatted with currency symbol. - name: profitMargin | type: number | description: Profit Margin. Calculated by dividing `profit` by `discounted_price`. The result is rounded to 4 decimal places. - name: weight | type: number | description: Variant weight. - name: sku | type: string | description: Variant SKU (stock keeping unit). - name: visible | type: boolean | description: Whether the variant is visible to customers. - name: productDimensions | type: Dimensions | description: Product dimensions (length, width, height of the physical product). - name: length | type: string | description: Length. Measurement unit is handled at the system level (metric/imperial). - name: width | type: string | description: Width. Measurement unit is handled at the system level (metric/imperial). - name: height | type: string | description: Height. Measurement unit is handled at the system level (metric/imperial). - name: unit | type: DimensionsUnit | description: Unit of measurement for dimensions (length, width, height). - enum: - UNKNOWN_DIMENSIONS_UNIT: - MM: Millimeters. - CM: Centimeters. - M: Meters. - IN: Inches. - FT: Feet. - YD: Yards. - name: packageDimensions | type: Dimensions | description: Package dimensions (length, width, height of the shipping package). - name: stock | type: VariantStock | description: Variant inventory status. - name: trackQuantity | type: boolean | description: Whether inventory is being tracked. - name: quantity | type: integer | description: Quantity currently left in inventory. - name: inStock | type: boolean | description: Whether the product is currently in stock (relevant only when tracking manually). ``` ### Examples ### Update product variants ```javascript import { products } from "@wix/stores"; const productId = "1044e7e4-37d1-0705-c5b3-623baae212fd"; const variants = [ { choices: { Size: "S", Color: "Blue" }, price: 100 } ]; async function updateProductVariants() { const response = await products.updateProductVariants(productId, variants); } /* Promise resolves to: * { * "variants": [ * { * "_id": "00000000-0000-0020-0005-92338aaf6c4a", * "choices": { * "Size": "S", * "Color": "Blue" * }, * "variant": { * "priceData": { * "currency": "USD", * "price": 100, * "formatted": { * "price": "$100.00", * "discountedPrice": "$100.00" * } * }, * "visible": true * } * } * ] * } */ ``` ### Update the data of a variant (with $w) ```javascript /************************************** * Backend code - products.web.js/ts * **************************************/ import { Permissions, webMethod } from '@wix/web-methods'; import { products } from '@wix/stores'; export const updateVariantData = webMethod(Permissions.Anyone, (_id, variants) => { return products.updateProductVariants(_id, variants); }); /************* * Page code * *************/ import { updateVariantData } from 'backend/products.web'; // ... $w('#myProductPage').getProduct() .then((product) => { let _id = product._id; let manageVariants = product.manageVariants; // check that variants can be added and updated // for this product if (manageVariants) { const weight = 10; const price = 15; const variants = [{ weight, price, "choices": { "Color": "Blue", "Size": "Large" } }]; updateVariantData(_id, variants) .then(() => { // product variant data have been updated }) .catch((error) => { // there was an error updating the product variant }); } }); ``` ### updateProductVariants (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { products } from '@wix/stores'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { products }, // Include the auth strategy and host as relevant }); async function updateProductVariants(_id,variants) { const response = await myWixClient.products.updateProductVariants(_id,variants); }; ``` ---