Custom Data (Metafields)
Extend any Cartly entity — products, variants, orders, customers — with custom structured data using Metafields.
Overview
Metafields let you attach custom key-value data to any entity in Cartly. Each metafield is scoped to a namespace (usually your app slug) and a key, so different apps never collide.
- Attach to products, variants, orders, customers, collections, pages
- Strongly typed values: string, integer, boolean, json, url, color, date
- Readable in Liquid templates and GraphQL Storefront API
- Managed via Admin REST API or admin UI
Namespaces & Keys
Use your app slug as the namespace to avoid conflicts with other apps or Cartly built-ins. Keys should be lowercase snake_case.
my_app.warranty_years— safe, namespacedglobal.color— reserved for Cartly built-ins
Value Types
Supported metafield types:
string— plain textinteger— whole numberboolean—true/falsejson— arbitrary JSON object or arrayurl— validated URLcolor— hex color (#ff6600)date— ISO 8601 date string
API Reference
Create or update a metafield on any entity:
// Create a metafield on a product
const response = await fetch(
`https://cartly.pro/admin/products/${productId}/metafields`,
{
method: "POST",
headers: {
"Authorization": `Bearer ${adminToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
namespace: "my_app",
key: "warranty_years",
value: "3",
type: "integer",
}),
}
);
const metafield = await response.json();
// { id: "...", namespace: "my_app", key: "warranty_years", value: "3", type: "integer" }Reading in Storefront
Metafields are available in Liquid templates and the GraphQL Storefront API:
// Access metafields in Liquid templates
{{ product.metafields.my_app.warranty_years }}
// Or via GraphQL Storefront API
query ProductMetafields($slug: String!) {
product(slug: $slug) {
metafield(namespace: "my_app", key: "warranty_years") {
value
type
}
}
}