Caroline Schnapp 12/14/2009

New Feature: Metafields

We’re excited to announce that we’ve just rolled out the ability to attach metadata to a shop’s resources using the Shopify API. This means Shopify app developers can now store additional information about products, collections, orders, blogs, pages… and the shop itself. We’re calling this feature metafields.

For the time being, you can only add these metafields and edit them using the Shopify API. Some time from now, we will make it possible for a shop owner to manage them from the admin interface.

The ability to use metafields in a Shopify theme has already been implemented. So you can output and use metafields in your Liquid templates (including email templates), provided you’ve added them using the API.

Our API documentation has been updated to show you how to add, edit and delete metafields. Check out the API Documentation page on MetaFields.

A metafield consists of a namespace, a key, a value, and a description (optional). Use the namespace to group different metafields in a logical way. You can also specify that it is either an integer or a piece of text (a “string”). In this way, you’ll end up with the right type when you use it in your Liquid.

Say you’ve added to a product a metafield with the following attributes:

  • description: Author of book
  • namespace: book
  • key: author
  • value: Kurt Vonnegut
  • value_type: string

You can output the value of this metafield in product.liquid with this Liquid tag:

{{ }}

There is currently no limit imposed on how many metafields you can attach to any piece of content.

If you’re a Ruby on Rails developer, our shopify_api gem will get you started with adding metafields. Take a look at the Metafields module defined in shopify_api.rb.

Using the Metafields module, setting a metafield on a product is as easy as this:

product = ShopifyAPI::Product.find(product_id)
   :description => 'Author of book',
   :namespace => 'book',
   :key => 'author',
   :value => 'Kurt Vonnegut',
   :value_type => 'string'

Metafields can be used to further describe products, beyond the product description, type, vendor and tags. You can also use metafields to store a ‘teaser’ or ‘summary’ for a blog post.

App Store developers can also use metafields to share information between multiple applications.

The possibilities are limitless. We’re inviting you to share your ideas on how to use metafields with the rest of the Shopify’s community in our Community forums.

Update: Metafields can now be added to product variants as well.