# Update a variant

> Partially update a variant using JSON Merge Patch.

`PATCH /rest/api/products/{productId}/variants/{variantId}`

Updates the Product Variant resource.

Partially updates a variant. The body is a [JSON Merge Patch](https://datatracker.ietf.org/doc/html/rfc7396) document: any field you include replaces the current value, and any field you omit is left untouched.

> **Merge Patch semantics**
>
> Omit a field to leave it untouched, or send a new value to replace it. Non-nullable fields such as `sku` and `barcode` reject `null` - you can change them but not clear them.

## Headers

| Name                         | Type     | Required | Description                                                                                                                                      |
| ---------------------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `X-Flowkiwi-Organization-Id` | `string` | Yes      | The organization the request acts as. Determines the identity, permissions and ownership applied when reading or modifying data on the instance. |

## Path parameters

| Name        | Type     | Required | Description                |
| ----------- | -------- | -------- | -------------------------- |
| `productId` | `string` | Yes      | ProductResource identifier |
| `variantId` | `string` | Yes      | Product Variant identifier |

## Request body

| Property       | Type                                  | Required | Description                                                                                                                                                                                   |
| -------------- | ------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `barcode`      | `string`                              | -        | The barcode, unique UPC, or ISBN number for the product.                                                                                                                                      |
| `sku`          | `string`                              | -        | A unique identifier for the product variant.                                                                                                                                                  |
| `measurement`  | `EmbeddedMeasurementResource \| null` | -        | The measurement used to compute per-unit prices for the variant.                                                                                                                              |
| `optionValues` | `string[]`                            | -        | A list of `Option Value`, each one representing an option value associated with the variant.                                                                                                  |
| `medias`       | `Media[]`                             | -        | A list of `Media`, ordered by position. Only media of type "image" can be associated with a variant. Returned as IRI strings by default; pass `?expand=medias` to embed full `Media` objects. |

## Response

**200** - Product Variant resource updated

| Property        | Type                                  | Required | Description                                                                                                                                                                                     |
| --------------- | ------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `@context`      | `object`                              | -        |                                                                                                                                                                                                 |
| `@id`           | `string`                              | Yes      |                                                                                                                                                                                                 |
| `@type`         | `string`                              | Yes      |                                                                                                                                                                                                 |
| `id`            | `string`                              | -        | The resource's unique identifier (UUID).                                                                                                                                                        |
| `barcode`       | `string`                              | Yes      | The barcode, unique UPC, or ISBN number for the product.                                                                                                                                        |
| `sku`           | `string`                              | Yes      | A unique identifier for the product variant.                                                                                                                                                    |
| `measurement`   | `EmbeddedMeasurementResource \| null` | -        | The measurement used to compute per-unit prices for the variant.                                                                                                                                |
| `product`       | `string`                              | Yes      | The product resource it belongs to.                                                                                                                                                             |
| `optionValues`  | `string[]`                            | -        | A list of `Option Value`, each one representing an option value associated with the variant.                                                                                                    |
| `medias`        | `string[]`                            | -        | A list of `Media`, ordered by position. Only media of type "image" can be associated with a variant. Returned as IRI strings by default; pass `?expand=medias` to embed full `Media` objects.   |
| `resolvedPrice` | `ResolvedPriceResource \| null`       | -        | The price resolved for the current `resolveContext` (country, channel and instant). Null unless `resolveContext[country]`, `resolveContext[channel]` and `resolveContext[at]` are all provided. |
| `metafields`    | `string[]`                            | -        | Metafields owned by this variant. Serialized as IRI strings by default; pass `?expand=metafields` to embed full `MetafieldResource` objects.                                                    |
| `createdAt`     | `string`                              | -        | The date and time when the resource was created (ISO 8601 format).                                                                                                                              |
| `updatedAt`     | `string`                              | -        | The date and time when the resource was last modified (ISO 8601 format).                                                                                                                        |

## Errors

**400** - Invalid input

| Property   | Type             | Required | Description                                                                                                                          |
| ---------- | ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `@context` | `object`         | -        |                                                                                                                                      |
| `@id`      | `string`         | Yes      |                                                                                                                                      |
| `@type`    | `string`         | Yes      |                                                                                                                                      |
| `title`    | `string \| null` | -        | A short, human-readable summary of the problem.                                                                                      |
| `detail`   | `string \| null` | -        | A human-readable explanation specific to this occurrence of the problem.                                                             |
| `status`   | `number \| null` | -        |                                                                                                                                      |
| `instance` | `string \| null` | -        | A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced. |
| `type`     | `string`         | -        | A URI reference that identifies the problem type                                                                                     |

**403** - Access denied. The caller is missing one or more identity permissions required for this operation.

| Property             | Type       | Required | Description                                                                                                                                |
| -------------------- | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `@context`           | `object`   | -        |                                                                                                                                            |
| `@id`                | `string`   | Yes      |                                                                                                                                            |
| `@type`              | `string`   | Yes      |                                                                                                                                            |
| `type`               | `string`   | -        |                                                                                                                                            |
| `title`              | `string`   | -        |                                                                                                                                            |
| `status`             | `integer`  | -        |                                                                                                                                            |
| `detail`             | `string`   | -        |                                                                                                                                            |
| `missingPermissions` | `string[]` | -        | Identity permissions that the caller is missing for this operation. Present only when the 403 is caused by a denied identity:* permission. |

**404** - Not found

| Property   | Type             | Required | Description                                                                                                                          |
| ---------- | ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `@context` | `object`         | -        |                                                                                                                                      |
| `@id`      | `string`         | Yes      |                                                                                                                                      |
| `@type`    | `string`         | Yes      |                                                                                                                                      |
| `title`    | `string \| null` | -        | A short, human-readable summary of the problem.                                                                                      |
| `detail`   | `string \| null` | -        | A human-readable explanation specific to this occurrence of the problem.                                                             |
| `status`   | `number \| null` | -        |                                                                                                                                      |
| `instance` | `string \| null` | -        | A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced. |
| `type`     | `string`         | -        | A URI reference that identifies the problem type                                                                                     |

**422** - An error occurred

| Property     | Type             | Required | Description |
| ------------ | ---------------- | -------- | ----------- |
| `@context`   | `object`         | -        |             |
| `@id`        | `string`         | Yes      |             |
| `@type`      | `string`         | Yes      |             |
| `status`     | `integer`        | -        |             |
| `violations` | `object[]`       | -        |             |
| `detail`     | `string`         | -        |             |
| `type`       | `string`         | -        |             |
| `title`      | `string \| null` | -        |             |
| `instance`   | `string \| null` | -        |             |

## Examples

### Example request

```bash
curl -X PATCH 'https://<tenant>.product-management.flowkiwi.net/rest/api/products/<product_id>/variants/<variant_id>' \
  -H 'Authorization: Bearer {token}' \
  -H 'X-Flowkiwi-Organization-Id: <org_id>' \
  -H 'Accept: application/ld+json' \
  -H 'Content-Type: application/merge-patch+json' \
  -d '{
  "measurement": {
    "measuredType": "weight",
    "quantityUnit": "g",
    "quantityValue": 500,
    "referenceUnit": "kg",
    "referenceValue": 1
  }
}'
```

### Example response

```json
{
  "@context": "/rest/api/contexts/Variant",
  "@id": "/rest/api/Variants/99de8700-b7f4-5734-b577-d530dfb9073a",
  "@type": "Variant",
  "id": "99de8700-b7f4-5734-b577-d530dfb9073a",
  "barcode": "BAR-001-A",
  "sku": "SKU-ABC-001",
  "measurement": {
    "measuredType": "weight",
    "quantityUnit": "g",
    "quantityValue": 500,
    "referenceUnit": "kg",
    "referenceValue": 1
  },
  "product": "/rest/api/products/fde4bd3c-1a15-5c83-9405-2d58145da17d",
  "optionValues": [
    "/rest/api/optionValues/d9ba418c-f94c-5bf9-a965-84e6b697b81d",
    "/rest/api/optionValues/a94ae1c2-1982-51f9-8971-d65b46bc5236"
  ],
  "images": [],
  "createdAt": "2024-01-01T00:00:00+00:00",
  "updatedAt": "2024-01-01T00:00:00+00:00"
}
```
