# Set a metafield

> Store a metafield value on an owner record.
{/* generated:versioned-pages - edit _pm-authored, not this file */}

`POST /api/{ownerResource}/{ownerId}/metafields`

Creates a Metafield resource.

Stores a metafield value on the owner record identified by `ownerResource` and `ownerId`. Reference the [definition](/api/product-management/metafield-definitions/) the value belongs to and give it a `value` - it is validated against the definition's `type` and `validations`.

## Headers

| Name              | Type     | Required | Description                                                                                                      |
| ----------------- | -------- | -------- | ---------------------------------------------------------------------------------------------------------------- |
| `Flowkiwi-Locale` | `string` | -        | Specifies the locale for properties that support localization. If not provided, the default locale will be used. |

## Path parameters

| Name            | Type     | Required | Description                                                                                                                |
| --------------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------- |
| `ownerResource` | `string` | Yes      | The owner resource type the metafields are scoped to (e.g. "products", "variants"); must match the definition's ownerType. |
| `ownerId`       | `string` | Yes      | The id of the owner record the metafields belong to.                                                                       |

## Request body

| Property     | Type             | Required | Description                                                                                                                                |
| ------------ | ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `definition` | `string`         | Yes      | The `MetafieldDefinition` this metafield is an instance of. Requires the `metafields:read` scope. Returned null when the scope is missing. |
| `value`      | `string \| null` | Yes      |                                                                                                                                            |

## Response

**201** - Metafield resource created

| Property        | Type               | Required | Description                                                                                                                                                                                                                             |
| --------------- | ------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `@context`      | `string \| object` | -        |                                                                                                                                                                                                                                         |
| `@id`           | `string`           | Yes      |                                                                                                                                                                                                                                         |
| `@type`         | `string`           | Yes      |                                                                                                                                                                                                                                         |
| `createdAt`     | `string`           | -        | The date and time when the resource was created (ISO 8601 format).                                                                                                                                                                      |
| `definition`    | `string \| null`   | -        | The `MetafieldDefinition` this metafield is an instance of. Requires the `metafields:read` scope. Returned null when the scope is missing.                                                                                              |
| `id`            | `string`           | -        | The resource's unique identifier (UUID).                                                                                                                                                                                                |
| `metaobject`    | `array`            | -        | The referenced metaobject(s). Populated when ?expand=metaobject is requested and the field type is metaobject_reference or list__metaobject_reference. Requires the `metaobjects:read` scope. Returned empty when the scope is missing. |
| `ownerId`       | `string \| null`   | -        | The id of the owner record the metafield is attached to.                                                                                                                                                                                |
| `ownerResource` | `string`           | Yes      | The type of resource that the metafield is attached to.                                                                                                                                                                                 |
| `updatedAt`     | `string`           | -        | The date and time when the resource was last modified (ISO 8601 format).                                                                                                                                                                |
| `value`         | `string`           | -        | **This property supports translations.**<br><br>The data stored in the metafield. Always stored as a string, regardless of the metafield's type.                                                                                        |

## 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`           | -        |                                                                                                                        |

**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 POST 'https://<tenant>.product-management.flowkiwi.net/api/{ownerResource}/{ownerId}/metafields' \
  -H 'Authorization: Bearer {access_token}' \
  -H 'Flowkiwi-Api-Version: unstable' \
  -H 'Accept: application/ld+json' \
  -H 'Content-Type: application/ld+json' \
  -d '{
  "definition": "/api/metafield_definitions/019afb01-1a2b-7c3d-8e4f-0a1b2c3d4e5f",
  "value": "Machine wash cold at 30°C"
}'
```

### Example response

```json
{
  "@context": "/api/contexts/Metafield",
  "@id": "/api/products/019af93e-420e-79f8-800b-6680f03dce20/metafields/019afb02-2b3c-7d4e-9f50-1a2b3c4d5e6f",
  "@type": "Metafield",
  "createdAt": "2026-01-15T09:30:00+00:00",
  "definition": "/api/metafield_definitions/019afb01-1a2b-7c3d-8e4f-0a1b2c3d4e5f",
  "id": "019afb02-2b3c-7d4e-9f50-1a2b3c4d5e6f",
  "metaobject": [],
  "ownerId": "019af93e-420e-79f8-800b-6680f03dce20",
  "ownerResource": "products",
  "updatedAt": "2026-02-03T14:45:12+00:00",
  "value": "Machine wash cold at 30°C"
}
```
