# Update a variant

> Partially update a variant using JSON Merge Patch.
{/* generated:versioned-pages - edit _pm-authored, not this file */}

`PATCH /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.

## 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.                                                                                                                                                                                                                  |
| `measurement`  | `EmbeddedMeasurementResource \| null` | -        | The measurement used to compute per-unit prices for 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. Requires the `medias:read` scope. Returned empty when the scope is missing. |
| `optionValues` | `string[]`                            | -        | A list of `Option Value`, each one representing an option value associated with the variant. Requires the `products:read` scope. Returned empty when the scope is missing.                                                                                                |
| `sku`          | `string`                              | -        | A unique identifier for the product variant.                                                                                                                                                                                                                              |

## Response

**200** - Product Variant resource updated

| Property        | Type                                  | Required | Description                                                                                                                                                                                                                                                               |
| --------------- | ------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `@context`      | `string \| object`                    | -        |                                                                                                                                                                                                                                                                           |
| `@id`           | `string`                              | Yes      |                                                                                                                                                                                                                                                                           |
| `@type`         | `string`                              | Yes      |                                                                                                                                                                                                                                                                           |
| `barcode`       | `string`                              | Yes      | The barcode, unique UPC, or ISBN number for the product.                                                                                                                                                                                                                  |
| `createdAt`     | `string`                              | -        | The date and time when the resource was created (ISO 8601 format).                                                                                                                                                                                                        |
| `id`            | `string`                              | -        | The resource's unique identifier (UUID).                                                                                                                                                                                                                                  |
| `measurement`   | `EmbeddedMeasurementResource \| null` | -        | The measurement used to compute per-unit prices for the variant.                                                                                                                                                                                                          |
| `medias`        | `array`                               | -        | 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. Requires the `medias:read` scope. Returned empty when the scope is missing. |
| `metafields`    | `array`                               | -        | Metafields owned by this variant. Serialized as IRI strings by default; pass `?expand=metafields` to embed full `MetafieldResource` objects. Requires the `metafields:read` scope. Returned empty when the scope is missing.                                              |
| `optionValues`  | `array`                               | -        | A list of `Option Value`, each one representing an option value associated with the variant. Requires the `products:read` scope. Returned empty when the scope is missing.                                                                                                |
| `product`       | `string \| Product \| null`           | Yes      | The product resource it belongs to. Requires the `products:read` scope. Returned null when the scope is missing.                                                                                                                                                          |
| `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.                                                                           |
| `sku`           | `string`                              | Yes      | A unique identifier for the product variant.                                                                                                                                                                                                                              |
| `updatedAt`     | `string`                              | -        | The date and time when the resource was last modified (ISO 8601 format).                                                                                                                                                                                                  |

## Errors

**400** - Invalid input

| Property      | Type               | Required | Description                                                                                                                          |
| ------------- | ------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `@context`    | `string \| object` | -        |                                                                                                                                      |
| `@id`         | `string`           | Yes      |                                                                                                                                      |
| `@type`       | `string`           | Yes      |                                                                                                                                      |
| `code`        | `string`           | -        | Stable identifier of the error in the error code catalogue (see /api/error-codes). Present on catalogued errors only.                |
| `description` | `string \| null`   | -        |                                                                                                                                      |
| `detail`      | `string \| null`   | -        | A human-readable explanation specific to this occurrence of the problem.                                                             |
| `instance`    | `string \| null`   | -        | A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced. |
| `message`     | `string`           | -        | End-user message localized in the request locale, with this occurrence's values substituted. Present on catalogued errors only.      |
| `slug`        | `string`           | -        | Stable, readable key of the error in the error code catalogue. Present on catalogued errors only.                                    |
| `status`      | `integer \| null`  | -        |                                                                                                                                      |
| `title`       | `string \| null`   | -        | A short, human-readable summary of the problem. For a catalogued error it repeats the `slug`.                                        |
| `type`        | `string`           | -        | A URI reference that identifies the problem type. For a catalogued error it is the error code resource, `/api/error-codes/{code}`.   |

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

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

**404** - Not found

| Property      | Type               | Required | Description                                                                                                                          |
| ------------- | ------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `@context`    | `string \| object` | -        |                                                                                                                                      |
| `@id`         | `string`           | Yes      |                                                                                                                                      |
| `@type`       | `string`           | Yes      |                                                                                                                                      |
| `code`        | `string`           | -        | Stable identifier of the error in the error code catalogue (see /api/error-codes). Present on catalogued errors only.                |
| `description` | `string \| null`   | -        |                                                                                                                                      |
| `detail`      | `string \| null`   | -        | A human-readable explanation specific to this occurrence of the problem.                                                             |
| `instance`    | `string \| null`   | -        | A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced. |
| `message`     | `string`           | -        | End-user message localized in the request locale, with this occurrence's values substituted. Present on catalogued errors only.      |
| `slug`        | `string`           | -        | Stable, readable key of the error in the error code catalogue. Present on catalogued errors only.                                    |
| `status`      | `integer \| null`  | -        |                                                                                                                                      |
| `title`       | `string \| null`   | -        | A short, human-readable summary of the problem. For a catalogued error it repeats the `slug`.                                        |
| `type`        | `string`           | -        | A URI reference that identifies the problem type. For a catalogued error it is the error code resource, `/api/error-codes/{code}`.   |

**422** - An error occurred

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

## Examples

### Example request

```bash
curl -X PATCH 'https://<tenant>.product-management.flowkiwi.net/api/products/<product_id>/variants/<variant_id>' \
  -H 'Authorization: Bearer {access_token}' \
  -H 'Flowkiwi-Api-Version: unstable' \
  -H 'Accept: application/ld+json' \
  -H 'Content-Type: application/merge-patch+json' \
  -d '{
  "optionValues": [
    "/api/product_options/019af941-6b7c-7d8e-9f0a-2b3c4d5e6f70/option_values/e99b2cf9-fcea-5da3-b2ac-4a9f5e956928"
  ]
}'
```

### Example response

```json
{
  "@context": "/api/contexts/Product%20Variant",
  "@id": "/api/products/019af93e-420e-79f8-800b-6680f03dce20/variants/b8da3511-02af-5f93-9fa6-78dad5ee48ac",
  "@type": "Product Variant",
  "barcode": "BAR-001-A",
  "createdAt": "2024-01-01T00:00:00+00:00",
  "id": "b8da3511-02af-5f93-9fa6-78dad5ee48ac",
  "measurement": {
    "measuredType": "weight",
    "quantityUnit": "g",
    "quantityValue": 500,
    "referenceUnit": "kg",
    "referenceValue": 1
  },
  "medias": [],
  "optionValues": [
    "/api/product_options/019af941-6b7c-7d8e-9f0a-2b3c4d5e6f70/option_values/e44abe10-be24-5761-8b5c-60449673a513",
    "/api/product_options/019af941-6b7c-7d8e-9f0a-2b3c4d5e6f70/option_values/8d49ea97-1fbb-5c9d-aff0-7b404cbf6de8"
  ],
  "product": "/api/products/019af93e-420e-79f8-800b-6680f03dce20",
  "sku": "SKU-ABC-001",
  "updatedAt": "2024-01-01T00:00:00+00:00"
}
```
