--- title: Metafields description: The API for interacting with metafields. api_version: 2025-01 api_name: customer-account-ui-extensions source_url: html: https://shopify.dev/docs/api/customer-account-ui-extensions/2025-01/apis/order-status-api/metafields md: https://shopify.dev/docs/api/customer-account-ui-extensions/2025-01/apis/order-status-api/metafields.md --- # MetafieldsAPI Requires access to [protected customer data](https://shopify.dev/docs/apps/store/data-protection/protected-customer-data) for some properties. The API for interacting with metafields. ## OrderStatusApi The API object provided to this and other `customer-account.order-status` extension targets. * appMetafields StatefulRemoteSubscribable\ required The metafields requested in the [`shopify.ui.extension.toml`](https://shopify.dev/docs/api/checkout-ui-extensions/configuration) file. These metafields are updated when there's a change in the merchandise items being purchased by the customer. [](https://shopify.dev/apps/store/data-protection/protected-customer-data)Requires access to [protected customer data](https://shopify.dev/docs/apps/store/data-protection/protected-customer-data). * metafields StatefulRemoteSubscribable\ required The metafields that apply to the current order. The actual resource on which these metafields exist depends on the source of the order: * If the source is an order, then the metafields are on the order. * If the source is a draft order, then the initial value of metafields are from the draft order, and any new metafields you write are applied to the order created by the checkout. * For all other sources, the metafields are only stored locally on the client creating the checkout, and are applied to the order that results from checkout. These metafields are shared by all extensions running on checkout, and persist for as long as the customer is working on this checkout. Once the order is created, you can query these metafields using the [GraphQL Admin API](https://shopify.dev/docs/admin-api/graphql/reference/orders/order#metafield-2021-01) ### AppMetafieldEntry A metafield associated with the shop or a resource on the checkout. * metafield The metadata information. ```ts AppMetafield ``` * target The target that is associated to the metadata. {% include /apps/checkout/privacy-icon.md %} Requires access to \[protected customer data]\(/docs/apps/store/data-protection/protected-customer-data) when the type is \`customer\`, \`company\` or \`companyLocation\`. ```ts AppMetafieldEntryTarget ``` ```ts export interface AppMetafieldEntry { /** * The target that is associated to the metadata. * * {% include /apps/checkout/privacy-icon.md %} Requires access to [protected customer data](/docs/apps/store/data-protection/protected-customer-data) when the type is `customer`, `company` or `companyLocation`. */ target: AppMetafieldEntryTarget; /** The metadata information. */ metafield: AppMetafield; } ``` ### AppMetafield Represents a custom metadata attached to a resource. * key The key name of a metafield. ```ts string ``` * namespace The namespace for a metafield. ```ts string ``` * type The metafield's type name. ```ts string ``` * value The value of a metafield. ```ts string | number | boolean ``` * valueType The metafield’s information type. ```ts 'boolean' | 'float' | 'integer' | 'json_string' | 'string' ``` ```ts export interface AppMetafield { /** The key name of a metafield. */ key: string; /** The namespace for a metafield. */ namespace: string; /** The value of a metafield. */ value: string | number | boolean; /** The metafield’s information type. */ valueType: 'boolean' | 'float' | 'integer' | 'json_string' | 'string'; /** The metafield's type name. */ type: string; } ``` ### AppMetafieldEntryTarget The metafield owner. * id The numeric owner ID that is associated with the metafield. ```ts string ``` * type The type of the metafield owner. {% include /apps/checkout/privacy-icon.md %} Requires access to \[protected customer data]\(/docs/apps/store/data-protection/protected-customer-data) when the type is \`customer\`, \`company\` or \`companyLocation\`. ```ts | 'customer' | 'product' | 'shop' | 'variant' | 'company' | 'companyLocation' | 'cart' ``` ```ts export interface AppMetafieldEntryTarget { /** * The type of the metafield owner. * * {% include /apps/checkout/privacy-icon.md %} Requires access to [protected customer data](/docs/apps/store/data-protection/protected-customer-data) when the type is `customer`, `company` or `companyLocation`. */ type: | 'customer' | 'product' | 'shop' | 'variant' | 'company' | 'companyLocation' | 'cart'; /** The numeric owner ID that is associated with the metafield. */ id: string; } ``` ### Metafield Metadata associated with the checkout. * key The name of the metafield. It must be between 3 and 30 characters in length (inclusive). ```ts string ``` * namespace A container for a set of metafields. You need to define a custom namespace for your metafields to distinguish them from the metafields used by other apps. This must be between 2 and 20 characters in length (inclusive). ```ts string ``` * value The information to be stored as metadata. ```ts string | number ``` * valueType The metafield’s information type. ```ts 'integer' | 'string' | 'json_string' ``` ```ts export interface Metafield { /** * The name of the metafield. It must be between 3 and 30 characters in * length (inclusive). */ key: string; /** * A container for a set of metafields. You need to define a custom * namespace for your metafields to distinguish them from the metafields * used by other apps. This must be between 2 and 20 characters in length (inclusive). */ namespace: string; /** * The information to be stored as metadata. */ value: string | number; /** The metafield’s information type. */ valueType: 'integer' | 'string' | 'json_string'; } ``` ## use​App​Metafields([filters](#useappmetafields-propertydetail-filters)​) Returns the metafields configured with `shopify.extension.toml`. ### Parameters * filters AppMetafieldFilters Default: {} ### Returns * AppMetafieldEntry\[] ### AppMetafieldFilters * id ```ts string ``` * key ```ts string ``` * namespace ```ts string ``` * type ```ts "variant" | "customer" | "product" | "shop" | "company" | "companyLocation" | "cart" ``` ```ts interface AppMetafieldFilters { id?: AppMetafieldEntryTarget['id']; type?: AppMetafieldEntryTarget['type']; namespace?: Metafield['namespace']; key?: Metafield['key']; } ``` ### AppMetafieldEntry A metafield associated with the shop or a resource on the checkout. * metafield The metadata information. ```ts AppMetafield ``` * target The target that is associated to the metadata. {% include /apps/checkout/privacy-icon.md %} Requires access to \[protected customer data]\(/docs/apps/store/data-protection/protected-customer-data) when the type is \`customer\`, \`company\` or \`companyLocation\`. ```ts AppMetafieldEntryTarget ``` ```ts export interface AppMetafieldEntry { /** * The target that is associated to the metadata. * * {% include /apps/checkout/privacy-icon.md %} Requires access to [protected customer data](/docs/apps/store/data-protection/protected-customer-data) when the type is `customer`, `company` or `companyLocation`. */ target: AppMetafieldEntryTarget; /** The metadata information. */ metafield: AppMetafield; } ``` ### AppMetafield Represents a custom metadata attached to a resource. * key The key name of a metafield. ```ts string ``` * namespace The namespace for a metafield. ```ts string ``` * type The metafield's type name. ```ts string ``` * value The value of a metafield. ```ts string | number | boolean ``` * valueType The metafield’s information type. ```ts 'boolean' | 'float' | 'integer' | 'json_string' | 'string' ``` ```ts export interface AppMetafield { /** The key name of a metafield. */ key: string; /** The namespace for a metafield. */ namespace: string; /** The value of a metafield. */ value: string | number | boolean; /** The metafield’s information type. */ valueType: 'boolean' | 'float' | 'integer' | 'json_string' | 'string'; /** The metafield's type name. */ type: string; } ``` ### AppMetafieldEntryTarget The metafield owner. * id The numeric owner ID that is associated with the metafield. ```ts string ``` * type The type of the metafield owner. {% include /apps/checkout/privacy-icon.md %} Requires access to \[protected customer data]\(/docs/apps/store/data-protection/protected-customer-data) when the type is \`customer\`, \`company\` or \`companyLocation\`. ```ts | 'customer' | 'product' | 'shop' | 'variant' | 'company' | 'companyLocation' | 'cart' ``` ```ts export interface AppMetafieldEntryTarget { /** * The type of the metafield owner. * * {% include /apps/checkout/privacy-icon.md %} Requires access to [protected customer data](/docs/apps/store/data-protection/protected-customer-data) when the type is `customer`, `company` or `companyLocation`. */ type: | 'customer' | 'product' | 'shop' | 'variant' | 'company' | 'companyLocation' | 'cart'; /** The numeric owner ID that is associated with the metafield. */ id: string; } ``` ## use​Metafield([filters](#usemetafield-propertydetail-filters)​) Returns a single filtered `Metafield` or `undefined`. ### Parameters * filters MetafieldFilter required ### Returns * Metafield | undefined ### MetafieldFilter * key ```ts string ``` * namespace ```ts string ``` ```ts interface MetafieldFilter { namespace: string; key: string; } ``` ### Metafield Metadata associated with the checkout. * key The name of the metafield. It must be between 3 and 30 characters in length (inclusive). ```ts string ``` * namespace A container for a set of metafields. You need to define a custom namespace for your metafields to distinguish them from the metafields used by other apps. This must be between 2 and 20 characters in length (inclusive). ```ts string ``` * value The information to be stored as metadata. ```ts string | number ``` * valueType The metafield’s information type. ```ts 'integer' | 'string' | 'json_string' ``` ```ts export interface Metafield { /** * The name of the metafield. It must be between 3 and 30 characters in * length (inclusive). */ key: string; /** * A container for a set of metafields. You need to define a custom * namespace for your metafields to distinguish them from the metafields * used by other apps. This must be between 2 and 20 characters in length (inclusive). */ namespace: string; /** * The information to be stored as metadata. */ value: string | number; /** The metafield’s information type. */ valueType: 'integer' | 'string' | 'json_string'; } ``` ## use​Metafields([filters](#usemetafields-propertydetail-filters)​) Returns the current array of `metafields` applied to the checkout. You can optionally filter the list. ### Parameters * filters MetafieldsFilters ### Returns * Metafield\[] ### MetafieldsFilters * key ```ts string ``` * namespace ```ts string ``` ```ts interface MetafieldsFilters { namespace: string; key?: string; } ``` ### Metafield Metadata associated with the checkout. * key The name of the metafield. It must be between 3 and 30 characters in length (inclusive). ```ts string ``` * namespace A container for a set of metafields. You need to define a custom namespace for your metafields to distinguish them from the metafields used by other apps. This must be between 2 and 20 characters in length (inclusive). ```ts string ``` * value The information to be stored as metadata. ```ts string | number ``` * valueType The metafield’s information type. ```ts 'integer' | 'string' | 'json_string' ``` ```ts export interface Metafield { /** * The name of the metafield. It must be between 3 and 30 characters in * length (inclusive). */ key: string; /** * A container for a set of metafields. You need to define a custom * namespace for your metafields to distinguish them from the metafields * used by other apps. This must be between 2 and 20 characters in length (inclusive). */ namespace: string; /** * The information to be stored as metadata. */ value: string | number; /** The metafield’s information type. */ valueType: 'integer' | 'string' | 'json_string'; } ```