> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - 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<variants> | 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)  | validation: format map
              - name: variantIds | type: array<string> | description: List of variant GUIDs (Not relevant when passing choices)  
              - name: price | type: number | description: Variant price  | validation: minimum 0, maximum 999999999.99, format double
              - name: cost | type: number | description: Variant cost of goods  | validation: minimum 0, maximum 999999999.99, format double
              - name: weight | type: number | description: Variant weight  | validation: minimum 0, maximum 999999999.99, format double
              - name: sku | type: string | description: Variant SKU (stock keeping unit)  | validation: maxLength 40
              - 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).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
                 - name: width | type: string | description: Width. Measurement unit is handled at the system level (metric/imperial).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
                 - name: height | type: string | description: Height. Measurement unit is handled at the system level (metric/imperial).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
                 - 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<Variant> | description: List of the product's variants.  
     - name: id | type: string | description: Requested Variant GUID  | validation: format GUID
     - name: choices | type: object | description: Specific choices within a selection, as option-choice key-value pairs  | validation: format map
     - name: variant | type: VariantDataWithNoStock | description:   
        - name: priceData | type: PriceData | description: Variant price.  
           - name: currency | type: string | description: Product price currency  | read-only: true 
           - name: price | type: number | description: Product price  | validation: minimum 0, maximum 999999999.99, format double
           - name: discountedPrice | type: number | description: Discounted product price (if no discounted price is set, the product price is returned)  | read-only: true 
           - name: formatted | type: FormattedPrice | description: The product price and discounted price, formatted with the currency  | read-only: true 
              - 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  | read-only: true 
           - name: pricePerUnit | type: number | description: Price per unit  | read-only: true | validation: format double
        - name: convertedPriceData | type: PriceData | description: Variant price data, converted to currency requested in header.  | read-only: true 
        - name: costAndProfitData | type: CostAndProfitData | description: Cost and profit data.  
           - name: itemCost | type: number | description: Item cost.  | validation: minimum 0, maximum 999999999.99, format double
           - name: formattedItemCost | type: string | description: Item cost formatted with currency symbol.  | read-only: true 
           - name: profit | type: number | description: Profit. Calculated by reducing `cost` from `discounted_price`.  | read-only: true | validation: minimum 0, maximum 999999999.99
           - name: formattedProfit | type: string | description: Profit formatted with currency symbol.  | read-only: true 
           - name: profitMargin | type: number | description: Profit Margin. Calculated by dividing `profit` by `discounted_price`. The result is rounded to 4 decimal places.  | read-only: true | validation: minimum 0, maximum 1
        - 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).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
           - name: width | type: string | description: Width. Measurement unit is handled at the system level (metric/imperial).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
           - name: height | type: string | description: Height. Measurement unit is handled at the system level (metric/imperial).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
           - 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.  | read-only: true 
        - name: trackQuantity | type: boolean | description: Whether inventory is being tracked.  
        - name: quantity | type: integer | description: Quantity currently left in inventory.  | validation: minimum 0, maximum 99999, format int32
        - 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: <AUTH>'
~~~
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.stores.products.updateProductVariants(_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<VariantOverride> | 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)  | validation: format map
              - name: variantIds | type: array<string> | description: List of variant GUIDs (Not relevant when passing choices)  
              - name: price | type: number | description: Variant price  | validation: minimum 0, maximum 999999999.99
              - name: cost | type: number | description: Variant cost of goods  | validation: minimum 0, maximum 999999999.99
              - name: weight | type: number | description: Variant weight  | validation: minimum 0, maximum 999999999.99
              - name: sku | type: string | description: Variant SKU (stock keeping unit)  | validation: maxLength 40
              - 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).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
                 - name: width | type: string | description: Width. Measurement unit is handled at the system level (metric/imperial).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
                 - name: height | type: string | description: Height. Measurement unit is handled at the system level (metric/imperial).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
                 - 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<UpdateVariantsResponse>
  - name: variants | type: array<Variant> | description: List of the product's variants.  
     - name: _id | type: string | description: Requested Variant GUID  | validation: format GUID
     - name: choices | type: object | description: Specific choices within a selection, as option-choice key-value pairs  | validation: format map
     - name: variant | type: VariantDataWithNoStock | description:   
        - name: priceData | type: PriceData | description: Variant price.  
           - name: currency | type: string | description: Product price currency  | read-only: true 
           - name: price | type: number | description: Product price  | validation: minimum 0, maximum 999999999.99
           - name: discountedPrice | type: number | description: Discounted product price (if no discounted price is set, the product price is returned)  | read-only: true 
           - name: formatted | type: FormattedPrice | description: The product price and discounted price, formatted with the currency  | read-only: true 
              - 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  | read-only: true 
           - name: pricePerUnit | type: number | description: Price per unit  | read-only: true 
        - name: convertedPriceData | type: PriceData | description: Variant price data, converted to currency requested in header.  | read-only: true 
        - name: costAndProfitData | type: CostAndProfitData | description: Cost and profit data.  
           - name: itemCost | type: number | description: Item cost.  | validation: minimum 0, maximum 999999999.99
           - name: formattedItemCost | type: string | description: Item cost formatted with currency symbol.  | read-only: true 
           - name: profit | type: number | description: Profit. Calculated by reducing `cost` from `discounted_price`.  | read-only: true | validation: minimum 0, maximum 999999999.99
           - name: formattedProfit | type: string | description: Profit formatted with currency symbol.  | read-only: true 
           - name: profitMargin | type: number | description: Profit Margin. Calculated by dividing `profit` by `discounted_price`. The result is rounded to 4 decimal places.  | read-only: true | validation: minimum 0, maximum 1
        - 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).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
           - name: width | type: string | description: Width. Measurement unit is handled at the system level (metric/imperial).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
           - name: height | type: string | description: Height. Measurement unit is handled at the system level (metric/imperial).  | validation: decimalValue {"gte":"0","lte":"999999999","maxScale":6}
           - 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.  | read-only: true 
        - name: trackQuantity | type: boolean | description: Whether inventory is being tracked.  
        - name: quantity | type: integer | description: Quantity currently left in inventory.  | validation: minimum 0, maximum 99999, format int32
        - 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-managed)
Self-managed 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);
};
```

---