API Metafield

From Spiffy Stores Knowledge Base

The Spiffy Stores API Metafield object allows you to attach metadata to a number of your Store's objects.

In this context, metadata represents any sort of data that can be represented by a key/value structure and can be associated with one of the following types of store objects.

  • Store
  • Product
  • Variation
  • Page
  • Blog
  • Standard Collection
  • Super Collection
  • Customer
  • Order

A Metafield has the following properties:

  • Namespace
  • Key
  • Value
  • Value Type (integer or string)
  • Description (Optional)

The Namespace allows you to group a number of related keys together.

Within a Namespace, there will be one or more unique Keys.

Each Key within the Namespace will have a Value which may be either an integer or string value.

Finally, for documentation purposes, an optional Description may also be added when the Metafield is created.

Metafields have many uses. For example, they allow you to store additional information about a product, that is specific to a certain type of product. You could use Metafields to associate products to a specific set of accessories for that product. Metafields provide a generic customization capabilities that allow you to organize your store's products, customers, orders and other content in any way that suits your particular needs.

Accessing a Metafield

Metafields can be created and associated with your Store. These sort of Metafields are global as only one instance of a store exists.

You can manage these sort of Metafields using the following types of API calls -

GET /api/metafields.json
GET /api/metafields/12345.json

and so on…

Metafields may also be associated with individual instances of store objects. In these cases, the Metafields are created when the object is created or added at a later time.

In order to manage these sort of Metafields, the object to which they belong must be referenced in the API call. For example -

GET /api/products/56789/metafields.json
GET /api/products/56789/metafields/24234.json

or

GET /api/variations/36789/metafields.json
GET /api/variations/36789/metafields/34523.json

or

GET /api/pages/234234/metafields.json
GET /api/pages/234234/metafields/456656.json

or

GET /api/blogs/86868/metafields.json
GET /api/blogs/86868/metafields/23423.json

or

GET /api/standard_collections/886789/metafields.json
GET /api/standard_collections/886789/metafields/67435.json

or

GET /api/super_collections/996789/metafields.json
GET /api/super_collections/996789/metafields/126575.json

or

GET /api/customers/56222/metafields.json
GET /api/customers/56222/metafields/12775.json

or

GET /api/orders/56111/metafields.json
GET /api/orders/56111/metafields/133325.json