# Update a variant

Source: https://developers.swell.is/backend-api/variants/update-a-variant

Update an existing product using the ID that was returned when created. Updating performs a merge operation. To explicitly override values such as arrays, use the `$set` operator.

## Arguments

- `id` (objectId, required): Unique identifier for the variant.
- `parent_id` (objectId): The id of the parent product.
- `active` (boolean): An active variant is visible to customers in a storefront, otherwise it will be hidden from view.
- `attributes` (object): An object containing custom attribute values. Overrides product attributes. See [attributes](https://developers.swell.is/frontend-api/attributes) for more details.
- `name` (string): Human-friendly name of the variant. Defaults to the combined name of all options, for example, "Blue, Large" in the case of 2 options; color and size.
- `price` (currency): List price used by default when `sale=false` or `sale_price` is not defined. Overrides product price.
- `archived` (boolean): A variant is automatically archived when it has been sold in the past and product options are changed in a way that would cause the variant to be removed.
- `cost` (currency): Cost of goods used to calculate gross margins. Overrides product cost.
- `images` (object): List of images depicting the variant.
  - `caption` (string): A brief description of the image.
  - `file` (object): An object representing the image file.
    - `data` (file): A reference to the raw file data.
    - `filename` (string): Optional file name.
- `prices` (array of object): Price rules to override `price` and `sale_price` when conditions match quantity or account group in a cart. Overrides product prices.
  - `price` (currency): Price applied when conditions are met.
  - `account_group` (string): Customer account group as a condition to apply price.
  - `quantity_max` (int): Maximum quantity as a condition to apply price.
  - `quantity_min` (int): Minimum quantity as a condition to apply price.
- `sale` (boolean): Indicates the variant is on sale and `sale_price` is used by default when the product is added to a cart. Overrides product sale.
- `sale_price` (currency): Sale price used by default when `sale=true`, overriding `price`. Overrides product sale price.
- `shipment_weight` (float): If specified, shipping is calculated based on this shipping weight. Otherwise it will assume 1 lb/oz/kg depending on your default weight unit. Overrides product shipping weight.
- `sku` (string): Stock keeping unit (SKU) used to track inventory in a warehouse.

## Example request

`PUT /products:variants/:id`

**cURL**

```bash
$ curl https://api.swell.store/products:variants/5c8fb5e1ed2faf8c79da492a \
  -u store-id:secret-key \
  -d price=19.98 \
  -X PUT
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.put('/products:variants/{id}', {
  id: '5c8fb5e1ed2faf8c79da492a',
  price: 19.98,
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->put('/products:variants/{id}', [
  'id' => '5c8fb5e1ed2faf8c79da492a',
  'price' => 19.98,
]);
```

## Example response

```json
{
  "id": "5c8fb5e1ed2faf8c79da492a",
  "parent_id": "5ca24abb9c077817e5fe2b36",
  "name": "Blue, Small",
  "active": true,
  "currency": "USD",
  "date_created": "2019-04-01T00:00:00.000Z",
  "date_updated": "2019-04-01T00:00:00.000Z",
  "price": 19.98
}
```
