Shopify metafields API tutorial (2026): add custom fields to products from your own Shopify app with the GraphQL Admin API 2026-10 - create metafield definitions (types, validation, pinned in the admin, storefront access), set, read and delete product metafields, on a real development store. Shopify app development series, episode 7 - everything shown is real, nothing skipped.
What you'll learn
- Definitions vs values (namespace, key, type)
- metafieldDefinitionCreate / Update / Delete
- metafieldsSet: many values in one call, all or nothing
- Validation errors: 'Value has a maximum of 5', 'Value must be an integer', 'Type can't be blank'
- compareDigest: no more overwriting someone else's change (STALE_OBJECT)
- jsonValue, metafieldsDelete, Polaris web components
💻 Free source code for this episode: https://github.com/fayyaz315/shopify-app-development-2026/tree/ep07
3 quick fixes from this episode
Shopify metafieldsSet Errors: Type Can't Be Blank & Must Be an Integer
Shopify metafieldsSet (GraphQL 2026-10): three real errors - "Value must be an integer", "Value has a maximum of 400" (the definition's validation) and "Type can't be blank" (no definition, no type) - then the call that works, with typed jsonValue.
▶ 60-second video: https://youtube.com/shorts/xgX7wE1T0xc
Shopify Update Metafields API: Stop Overwriting Changes (compareDigest)
Shopify update metafields API (GraphQL 2026-10): someone changes a value while your app's page is open - without a check your save overwrites it. Send compareDigest with metafieldsSet and Shopify refuses the stale save with STALE_OBJECT. Real app, real error.
▶ 60-second video: https://youtube.com/shorts/jH7thkCd7zg
Shopify GraphQL Metafield Definition: Custom Fields on the Product Page
Shopify GraphQL metafield definition (2026-10): metafieldDefinitionCreate with a type, a validation and pin: true - my app sets the values with metafieldsSet and they show up on Shopify's own product page. Plus the error for a duplicate key.
▶ 60-second video: https://youtube.com/shorts/fZA1LAJ449I
Step by step
Preview + intro (0:00)
In the next ten minutes, you'll add your own fields to Shopify products, from inside your own app. Shopify checks every value against your rules, and one small field stops your app from overwriting someone else's change. This is the Shopify metafields API at work.
Material, care guide, warranty and features: four custom fields, set from our own app, right on Shopify's product page. This is episode seven of the Shopify app development series. Products, variants, collections, inventory and discounts are done.
Today: metafields. The full code is free on GitHub, and the link is in the description.
Definitions vs values (0:39)
First, what a metafield really is. There are two parts, and mixing them up is the most common mistake. The definition is like a column in a spreadsheet.
A name, a key, a type and some rules. Every product gets that column. The value is one cell: what this one product has in that column.
And the owner is what the value belongs to. Today it's products, but variants, customers, orders and collections work the same way. A metafield is found by three things.
The namespace, which is a group. The key, which is the field's name in code. And the type.
Together, namespace and key are unique for an owner type. Specs.material on products is one field, and only one. The type decides what's allowed: single line text, multi line text, an integer, a date, a list, a product reference, and many more.
The metafields page (1:38)
Now our app. A new Metafields page, still empty. On top, our product fields.
Below, the values of one product. A new page is a new file. The route file app.metafields becomes the URL /app/metafields.
The menu link is one more line in the app layout. No new permission this time. Product metafields are part of the products scope we already have.
Our app keeps all its fields in one namespace, specs. This dev store already has thirty seven product definitions from other apps and Shopify itself, so a namespace keeps ours apart. If you leave the namespace out, Shopify uses an app owned namespace, app dash dash and your app's ID.
Merchants can read those, but only your app can write them. Same request path as every episode: the page asks the loader, buttons call the action, and both talk to the Admin API.
Read: definitions and values (2:37)
Reading first. One query asks for two things. The definitions, with metafield definitions, filtered by owner type product and our namespace.
For each one: the key, the name, the type, the validations, whether it's pinned, how many products use it, and storefront access. And the values of one product, with product metafields in the same namespace. Value, json value and compare digest.
We'll need that last one later. The product select picks which product we edit. It reloads the page with the product ID in the URL, and the loader reads it from there.
The loader joins them. Every definition becomes a row, and gets this product's value, or null when it's empty. The maximum comes from the validations list, and pinned is simply a pinned position that isn't null.
The API in GraphiQL (3:29)
Before the app, the raw API in GraphiQL. metafieldDefinitionCreate: namespace specs, key fabric weight, type number integer. With two validations, minimum one hundred, maximum four hundred, and pin true.
Created, with its own ID. Now metafields set, on the Classic Oxford Shirt. I send the value one hundred twenty gsm, with the unit.
Refused. Value must be an integer. The definition's type is checked on every write.
Now twelve hundred, a typo with one zero too many. Value has a maximum of four hundred. The validation from the definition, enforced by Shopify for every app and every merchant.
Next, a key called fit that has no definition, and I don't send a type. Type can't be blank. Without a definition, Shopify can't guess the type, so you must send it.
With a definition, the type is optional. Shopify takes it from the definition, and a different type is refused as inconsistent. Now all three in one call: fabric weight one hundred twenty, fit with its type, and colors, a list, sent as a JSON array.
Three metafields back. Each one has a compare digest, a fingerprint of the current value. And reading them: product, metafields, namespace specs.
Value is always a string. Json value gives you the real type: the number one hundred twenty, and a real array of colors.
Create definitions (5:06)
Back in the app. Add field opens a form: a name, a key, and a type. Material, key material, single line text.
Show on the product page is already checked, and I tick themes can read it. Created. Admin and storefront badges.
In the action, create definition sends namespace, key, name, owner type product, the type, and the validations. Pin true shows the field on Shopify's product page. Storefront public read makes it readable on the storefront through the Storefront API.
The default is none. On the page, the modal has the name, the key and the type. The type select only shows when you create, because a type can't change later.
Care guide, with multi line text. Created. Warranty in years: an integer, with a maximum of five.
Created, and the type column says integer, zero to five. The maximum becomes two validations, min zero and max five. Validations are name and value pairs, always as strings.
And features, a list of text. Four fields, and every product in the store now has them.
Keys are unique (6:19)
A mistake on purpose: another field with the same key, material. Key is in use for product metafields on the specs namespace. One key per namespace and owner type.
Keys have rules too. A key with a space and an exclamation mark, like Care Guide, is refused: invalid character. In the action, every mutation returns userErrors, and the page shows Shopify's own message in a red toast.
Set values: metafieldsSet (6:46)
Now the values, for the Canvas Weekender Bag. Material: waxed cotton canvas. The care guide gets two lines.
The warranty: nine years, on purpose. And three features, separated by commas. Save values.
Value has a maximum of five. Our rule, checked by Shopify, not by our page. And nothing was saved, not even the material.
Metafields set is all or nothing: one bad value refuses the whole call. Two years, save. Values saved, and every field now shows one product.
Saving is one mutation for every field: metafields set. It creates a value if there's none, and updates it if there is. On the page, every field gets the right input.
A text area for multi line text, a number field for integers, and a text field for the rest. The action builds one input per filled field: owner ID, namespace, key and value. No type needed, because our definitions exist.
Values are strings. A list must be JSON, so to value splits the commas into a JSON array. Plain text with commas is refused as invalid JSON.
On Shopify's product page (8:06)
Now the real proof. Shopify's own product page for the weekender bag, down to product metafields. Features as three chips, warranty two, the care guide on two lines, and material.
Our definitions are pinned, so they show right here, and the merchant can edit them.
compareDigest: no lost updates (8:23)
Now a problem every real app has. Someone changes the material in the admin, while our page is still open with the old value. I type organic cotton canvas, and save.
Refused. The resource has been updated since it was loaded. Try again with an updated compare digest.
After a reload, the page shows the admin's change. Nothing was lost. That's compare digest.
The loader reads each value's digest, the page sends it back, and Shopify only saves if the value is still the same. On the page, saving sends each field's key, type and digest along with the form, as one JSON list. For an empty field we send null.
That means: create it only if it still doesn't exist. Without compare digest, the last save simply wins, and the merchant's change is gone without a word.
Edit, remove, delete (9:16)
Editing a definition. Warranty in years becomes just warranty, with a maximum of ten. Saved.
Integer, zero to ten. Update finds the definition by namespace, key and owner type. You can change the name and the rules, but not the type.
The update input simply has no type field. To change a type, you create a new definition and move the data. Remove deletes one value: the care guide of this product.
The definition stays, and the count drops to zero. That's metafields delete, with owner ID, namespace and key. Deleting a value that isn't there returns null, not an error.
And delete removes the features field from every product. Field deleted. Watch this flag: deleteAllAssociatedMetafields.
I tested it set to false: the definition goes, but every value stays behind, orphaned.
Honest notes (10:16)
A few honest notes before the recap. One: the values form covers four text and number types. Dates, references, colours and files need their own inputs.
Two: metafields are not for secrets. Values are plain text to any app with product access, and storefront access makes them public. Three: I tried searching products by a metafield value from the Admin API, and got nothing back, so I'm not showing that here.
Want to practise? Add a date field, like a launch date, or show the material on the storefront with Liquid: product.metafields.specs.material. And everything you saw was tested on my real development store, on API version 2026-10, before I pressed record.
Recap (11:04)
So, the recap. Define your fields once, with metafieldDefinitionCreate: namespace, key, type, rules and pin. Write values with metafields set, many at once, all or nothing, and send compare digest so you never overwrite someone else.
Read them with product metafields, and use json value for real numbers and lists. And clean up with metafields delete, or delete the definition with its values. That's the Shopify metafields API in 2026, inside a real app, on a real store.
The full code for this episode is free on GitHub. The link is in the description. Next episode: metaobjects.
Your own content types, like size charts or FAQs, with entries you can reuse. See you there.
📖 The full written tutorial with every episode: https://www.wixob.com/shopify-metafields-api-tutorial/
📚 Course page: https://www.wixob.com/shopify-app-development-2026/
🔔 New episodes on YouTube: https://www.youtube.com/@fayyaz-ahmed-shopify-developer?sub_confirmation=1
Questions about the Shopify GraphQL Admin API? Ask in the comments — I answer every one.


