To build a Shopify automated collection from a metafield, do two things in order. Turn on the metafield definition’s smartCollectionCondition capability, then create the collection with a typed metafield condition inside sources. From Admin API 2026-07 the older ruleSet rule with PRODUCT_METAFIELD_DEFINITION is deprecated, although it still runs.
Everything below was written against Admin GraphQL 2026-10, the latest stable version when we checked on 25 November 2026.
Which metafields can a Shopify automated collection use?
The typed inputs in CollectionSourceInclusionConditionInput are the full list. True or false definitions match with EQUALS. Integer and decimal definitions take EQUALS, GREATER_THAN or LESS_THAN. Single line text takes EQUALS only, and a list of single line text takes INCLUDES. A metaobject reference takes EQUALS, and a list of metaobject references takes INCLUDES.
Shopify’s metafield capabilities guide also lists rating definitions. We found no rating condition among the typed inputs and nothing in the reference saying which input accepts one, so try it on a development store before you promise it to anyone.
Two gaps should shape your data model. Text matching is exact, with no contains or starts-with, so Full-grain leather and leather are different values. And there is no not-equals relation. Exclusions cannot fill that hole, because exclusion conditions exist only for tag, type, vendor, category and other collections. A rule like “material is not leather” therefore needs a tag, which has both a NOT_TAGGED_WITH relation and an exclusion condition, and cannot be built from a metafield.
You do not have to memorise the type list. Every definition reports capabilities.smartCollectionCondition.eligible, and the script further down reads it before doing anything else.
There are two limits to plan around. The help centre says the option can be switched on for up to 128 product definitions and 128 variant definitions. The collections model guide allows 60 conditions per source and counts each value separately, so one text condition with five values uses five of them.
How do you enable a metafield as a collection condition?
A merchant does it in the admin: Settings, then Metafields and metaobjects, then the product or variant definition, where there is an option to use it as a condition in collections. From code it is metafieldDefinitionUpdate with capabilities.smartCollectionCondition.enabled set to true. The older useAsCollectionCondition boolean on the same input is deprecated in favour of the capability.
Three of the mutation’s error codes apply here. TYPE_NOT_ALLOWED_FOR_CONDITIONS means the type is not eligible. OWNER_TYPE_LIMIT_EXCEEDED_FOR_AUTOMATED_COLLECTIONS means the store has used up its definitions. APP_CONFIG_MANAGED means the definition is declared in an app’s configuration and cannot be changed through the API.
That last code matters to app developers because of what TOML leaves out. The capabilities guide says only adminFilterable, uniqueValues, cartToOrderCopyable and analyticsQueryable can be declared in TOML, so neither documented route gives a TOML-declared definition this capability. If an app-owned metafield has to drive collections, create its definition with metafieldDefinitionCreate and pass the capability there. It is one of the few definitions we would keep out of the app’s TOML file.
How do you create the collection through the API?
collectionCreate now takes a collection argument whose sources list holds the conditions. A condition points at the definition by ID, and definition IDs differ from store to store, so the script looks the definition up by namespace and key first. It enables the capability only when it is off, so a second run skips that mutation. A second run still creates a second collection.
// Env: SHOP=example.myshopify.com ADMIN_TOKEN=shpat_...
// Run: node metafield-collection.mjs custom.material leather suede
const API_VERSION = '2026-10';
const { SHOP, ADMIN_TOKEN } = process.env;
const [metafield = '', ...values] = process.argv.slice(2);
const [namespace, key] = metafield.split('.');
if (!SHOP || !ADMIN_TOKEN || !key || values.length === 0) {
console.error('Usage: node metafield-collection.mjs <namespace.key> <value> [value...]');
process.exit(1);
}
async function admin(query, variables) {
const res = await fetch(`https://${SHOP}/admin/api/${API_VERSION}/graphql.json`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Shopify-Access-Token': ADMIN_TOKEN },
body: JSON.stringify({ query, variables }),
});
const body = await res.json();
if (!res.ok || body.errors) {
throw new Error(`Admin API ${res.status}: ${JSON.stringify(body.errors)}`);
}
return body.data;
}
const identifier = { ownerType: 'PRODUCT', namespace, key };
const { metafieldDefinition: definition } = await admin(
`query FindDefinition($identifier: MetafieldDefinitionIdentifierInput!) {
metafieldDefinition(identifier: $identifier) {
id
type { name }
capabilities { smartCollectionCondition { eligible enabled } }
}
}`,
{ identifier },
);
if (!definition) throw new Error(`No product metafield definition for ${metafield}`);
const { eligible, enabled } = definition.capabilities.smartCollectionCondition;
if (!eligible) throw new Error(`${definition.type.name} cannot be a collection condition`);
if (!enabled) {
const { metafieldDefinitionUpdate: result } = await admin(
`mutation EnableCondition($definition: MetafieldDefinitionUpdateInput!) {
metafieldDefinitionUpdate(definition: $definition) {
updatedDefinition { id }
userErrors { field message code }
}
}`,
{ definition: { ...identifier, capabilities: { smartCollectionCondition: { enabled: true } } } },
);
if (result.userErrors.length > 0) throw new Error(JSON.stringify(result.userErrors));
}
const definitionId = definition.id;
const conditionByType = {
single_line_text_field: {
metafieldString: { definitionId, relation: 'EQUALS', matchType: 'ANY', values },
},
'list.single_line_text_field': {
metafieldStringList: { definitionId, relation: 'INCLUDES', matchType: 'ANY', values },
},
};
const condition = conditionByType[definition.type.name];
if (!condition) throw new Error(`This script only handles text, not ${definition.type.name}`);
const { collectionCreate: created } = await admin(
`mutation CreateCollection($collection: CollectionCreateInput!) {
collectionCreate(collection: $collection) {
collection { id handle }
userErrors { field message }
}
}`,
{
collection: {
title: `${key}: ${values.join(', ')}`,
sources: [
{
source: {
title: `${metafield} is ${values.join(' or ')}`,
inclusion: { matchType: 'ALL', conditions: [condition] },
},
},
],
},
},
);
if (created.userErrors.length > 0) throw new Error(JSON.stringify(created.userErrors));
console.log(`Created ${created.collection.id} (/collections/${created.collection.handle}), unpublished`);
Run it with node metafield-collection.mjs custom.material leather suede. Collection reads and writes need the read_products and write_products scopes. The new collection is unpublished, as the collectionCreate reference warns, so follow up with publishablePublish before looking for it on the storefront.
matchType appears twice and means different things. On inclusion it decides whether a product must satisfy all the conditions or any of them. Inside a text condition it decides whether the metafield must match all the listed values or any of them. A single-value text field cannot equal two strings at once, so keep that inner one on ANY unless the definition is a list.
For a variant metafield, change the script’s ownerType to PRODUCTVARIANT. The condition inputs take a definition ID and nothing else that distinguishes the two. By default a source targets PRODUCTS, which includes the whole product when any variant satisfies the conditions. Setting targetType to VARIANTS includes only the matching variants, and the guide caps those at 100 variant-level collections per shop.
Why does an integer condition break on the next API version?
Integer conditions were renamed between two consecutive versions. 2026-07 has metafieldInteger with a GraphQL Int value. 2026-10 adds metafieldInt, whose value is a string, and deprecates the old field with the reason that “Integer metafields support values beyond the range of GraphQL’s 32-bit Int”. The 2027-01 release candidate no longer has metafieldInteger at all.
{
"collection": {
"title": "Waterproof, five years or more",
"sources": [
{
"source": {
"title": "Feature and warranty metafields",
"inclusion": {
"matchType": "ALL",
"conditions": [
{
"metafieldStringList": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456140",
"relation": "INCLUDES",
"matchType": "ANY",
"values": ["waterproof"]
}
},
{
"metafieldInt": {
"definitionId": "gid://shopify/MetafieldDefinition/1071456141",
"relation": "GREATER_THAN",
"value": "4"
}
}
]
}
}
}
]
}
}
We checked those variables against the published schema of each version. 2026-07 rejects metafieldInt, 2026-10 accepts both spellings, and 2027-01 rejects metafieldInteger. An app that adopted sources on 2026-07 therefore has one version in which to switch, so add the rename to the checklist for your next quarterly version upgrade.
What happens to apps still writing ruleSet?
Nothing yet. This is the legacy form of a metafield rule, and it still validates on 2026-10 with a deprecation warning on the input argument:
mutation LegacyMetafieldCollection {
collectionCreate(
input: {
title: "Leather"
ruleSet: {
appliedDisjunctively: false
rules: [
{
column: PRODUCT_METAFIELD_DEFINITION
relation: EQUALS
condition: "leather"
conditionObjectId: "gid://shopify/MetafieldDefinition/1071456136"
}
]
}
}
) {
collection {
id
}
userErrors {
field
message
}
}
}
The translation is mechanical. column plus conditionObjectId becomes a typed condition with a definitionId, and appliedDisjunctively: false becomes matchType: ALL.
The risk for older apps is on the read side. According to the migration guide, a collection that uses anything the legacy shape cannot express (several sources, exclusions, variant targeting, a new condition type) is hidden from API versions before 2026-07. collection(id:) returns null with an HTTP 200 and no errors, and connection queries leave the collection out. The help centre already describes Products and Variants sources in the admin, so merchants can build such collections without your app being involved. An app pinned to 2026-04 that syncs collections will quietly miss them.
On 2026-07 and later, read Collection.sources with inline fragments per condition type, and handle CollectionSourceInclusionConditionUnknown, which is how a condition type added in a later version reaches an older client.
Should the collection run on a metafield or a tag?
Use a metafield when the attribute is structured: a number you compare, a metaobject reference, or text restricted to a fixed list of choices by a validation on the definition. Exact matching is safe when nobody can type a variation.
Stay with tags when the rule needs negation. For partial matches the candidates are title, type and vendor conditions, which take CONTAINS and STARTS_WITH.
Write new code against sources and stop adding ruleSet writes, since the June 2026 changelog entry marks the old shape deprecated. If your app reads collections on a version before 2026-07, move the reads first, because that is the half that fails silently.
Modelling a catalogue so collections fill themselves, and moving apps off ruleSet, is part of the Shopify development work we do for merchants and app teams.