# Create an option value

> Add a value to a product option.

`POST /rest/api/option_values`

Creates a Option Value resource.

Creates a value on a [Product Option](/api/product-management/options/) - for example *Medium* on a *Size* option. Point it at the option with the `productOption` IRI.

> **Linking to an option**
>
> `productOption` is the IRI of the option this value belongs to, e.g. `/rest/api/product_options/{productOptionId}`. The value's `position` controls its order within that option.

## 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.  |
| `X-Flowkiwi-Locale`          | `string`  | -        | Specifies the locale for properties that support localization. If not provided, the default locale will be used.                                  |
| `X-Flowkiwi-Locale-Fallback` | `boolean` | -        | Enables the use of a fallback locale. If a property lacks a translation for the requested locale, the value from the default locale will be used. |

## Request body

| Property        | Type              | Required | Description                                                                            |
| --------------- | ----------------- | -------- | -------------------------------------------------------------------------------------- |
| `value`         | `string \| null`  | Yes      | The value of the option.                                                               |
| `position`      | `integer \| null` | -        | The position of the option value. Use -1 to put the option value at the end.           |
| `productOption` | `string \| null`  | Yes      | The `Product Option` to which this option value belongs.                               |
| `variants`      | `string[]`        | -        | A list of `Variant`, each one representing a variant associated with the option value. |

## Response

**201** - Option Value resource created

| Property        | Type              | Required | Description                                                                            |
| --------------- | ----------------- | -------- | -------------------------------------------------------------------------------------- |
| `@context`      | `object`          | -        |                                                                                        |
| `@id`           | `string`          | Yes      |                                                                                        |
| `@type`         | `string`          | Yes      |                                                                                        |
| `id`            | `string`          | -        |                                                                                        |
| `value`         | `string \| null`  | Yes      | **This property supports translations.**<br><br>The value of the option.               |
| `position`      | `integer \| null` | -        | The position of the option value. Use -1 to put the option value at the end.           |
| `productOption` | `string`          | Yes      | The `Product Option` to which this option value belongs.                               |
| `variants`      | `string[]`        | -        | A list of `Variant`, each one representing a variant associated with the option value. |
| `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. |

**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 POST 'https://<tenant>.product-management.flowkiwi.net/rest/api/option_values' \
  -H 'Authorization: Bearer {token}' \
  -H 'X-Flowkiwi-Organization-Id: <org_id>' \
  -H 'Accept: application/ld+json' \
  -H 'Content-Type: application/ld+json' \
  -d '{
  "value": "Large",
  "productOption": "/rest/api/productOptions/083c8bb1-433e-5759-b739-39aec051f64c",
  "variants": [
    "/rest/api/variants/773134d8-52ab-576b-ab48-5a1544123bc5",
    "/rest/api/variants/96cc4b33-bb9b-5b47-b925-4356890a80fe"
  ]
}'
```

### Example response

```json
{
  "@context": "/rest/api/contexts/OptionValue",
  "@id": "/rest/api/OptionValues/b07ba094-3e69-5659-a1a5-a91fea989c50",
  "@type": "OptionValue",
  "id": "b07ba094-3e69-5659-a1a5-a91fea989c50",
  "value": "Large",
  "position": 0,
  "productOption": "/rest/api/productOptions/80572dcd-5c1a-5c29-b2d0-3748cb29283b",
  "variants": [
    "/rest/api/variants/bd8e2922-7c56-52c4-a870-bd0567b329df",
    "/rest/api/variants/dc1542af-880d-576a-84ec-3e0c660053a8"
  ],
  "createdAt": "2024-01-01T00:00:00+00:00",
  "updatedAt": "2024-01-01T00:00:00+00:00"
}
```
