Overview

Metafields are used to add custom data to SHOPLINE resources. You can store additional information for products, orders, customers, pages, and other resources, then retrieve or render that information in the SHOPLINE Admin, through the Open API, and in theme templates.


Use cases​

Metafields can be used to:

  • Maintain supplementary product information, such as material details, additional sizing information, and display fields.

  • Record business attributes for orders or customers, such as custom notes and workflow labels.

  • Display custom content on theme pages to support dynamic page content.


Metafield structure​

Each metafield includes the following information:

ItemDescription
ResourceThe resource type to which the metafield belongs. Refer to Resource types.
Resource IDThe resource ID to which the metafield belongs.
NamespaceThe namespace of the metafield. It cannot be changed after creation.
KeyThe unique identifier for the metafield within its namespace. It cannot be changed after creation.
Data typeThe data type of the metafield, such as single_line_text_field and number_integer. For more information, refer to Data types.
ValueThe value stored in the metafield. All values are stored as strings.
NameThe name of the associated metafield definition. It identifies the definition’s use case.
DescriptionThe description of the associated metafield definition.

Resource types​

Metafields support the following resource types:

Resource typeAPI valid valueDescription
ProductproductsAdds custom data to products. Supports management in the SHOPLINE Admin and through the Open API.
Product collectioncollectionsAdds custom data to product collections. Supports management in the SHOPLINE Admin and through the Open API.
Product variantvariantsAdds custom data to product variants. Supports management in the SHOPLINE Admin and through the Open API.
PagepagesAdds custom data to pages. Supports management in the SHOPLINE Admin and through the Open API.
CustomercustomersAdds custom data to customers. Supports management in the SHOPLINE Admin and through the Open API.
ArticlearticlesAdds custom data to articles. Supports management in the SHOPLINE Admin and through the Open API.
BlogblogsAdds custom data to blogs. Supports management in the SHOPLINE Admin and through the Open API.
OrderordersAdds custom data to orders. Supports management in the SHOPLINE Admin and through the Open API.
CompanycompaniesAdds custom data to companies. Management in the SHOPLINE Admin is available only for Enterprise stores. Supports management through the Open API.
StoreshopAdds custom data to the store. Supports management only through the Open API.

Metafield definitions​

A metafield definition specifies the metafields that a resource type can use and their data structures. A metafield definition is distinct from a metafield value on a specific resource instance. You can create a metafield definition to set the data type, configure data validation rules, and enable metafields to be displayed and managed in the SHOPLINE Admin. For temporary extensions or scenarios where the field model has not been determined, you can also write undefined metafields directly.

This section first explains how to create and manage metafield definitions. It then describes the differences and use cases for defined and undefined metafields when writing metafield values.

Management methods​

You can create and manage metafield definitions in the following ways. This section does not cover creating, querying, updating, or deleting metafield values.

Defined and undefined metafields​

When writing a metafield value, the resource type, namespace, key, and data type determine whether a corresponding metafield definition exists. There are two types of metafields:

Defined metafields​

If you need to centrally manage metafields with the same resource type, namespace, key, and data type, use the metafield definition APIs. For details, refer to Metafield definition guide.

Defined metafields support access control, collaboration in the SHOPLINE Admin, and consistent data management. This is the recommended approach.

Undefined metafields​

Undefined metafields are suitable for temporary extensions or scenarios where the field model has not been determined. You can use the Operate metafields in bulk API to write metafield values directly. Note that undefined metafields are not validated against data validation rules and are not recommended for long-term data storage.


Metafields SEO data optimization​

Value of meta tags​

Meta tags are text snippets that describe the content of a webpage. They usually consist of Meta Title and Meta Description.

Meta tags do not appear on the web page itself, but in the page's source code. Meta tags are essentially content descriptors that help inform search engines like Google about the content of the webpage.

Optimizing the meta tags of URLs within a store is beneficial for Google spiders to crawl, analyze, index, and improve the natural ranking on SERPs (Search Engine Results Pages). You can use OpenAPI to add, modify, query, or delete SEO data for all resources that have SEO information.

Prerequisites​

  • Familiarity with metafields and how they work.
  • Understanding of metafield's OpenAPI.

Managing SEO information​

You can manage the SEO information of resources through the merchant's back-end.

For example, after creating a product in the merchant's back-end, the meta_title and meta_description of the product detail page will be automatically populated with the product's title and description.

You have two methods to customize the page title and description for the product detail page:

  1. Edit the SEO information of the corresponding resource page through the merchant's back-end.
  2. Edit the SEO information of the corresponding resource page through Metafield's OpenAPI.

The meta_title and meta_description of the page are stored in the metafield with the namespace "seo" and the type single_line_text_field.

Editing SEO information for the corresponding resource page through metafield's OpenAPI​

Step 1: Use the Get metafields for a resource to query the metafield Id for the SEO metafields.

Step 2: Use the Update a metafield for a resource to edit the SEO information, following the storage format for SEO resources:

  • Namespace: seo
  • Keys: seoTitle, seoDescription
  • Resources:
    • Home Page: shop (The homepage SEO resource uses the shop resource's Metafield query/edit interface)
    • Products: products
    • Collections: collections
    • Blog Groups: blogs
    • Blogs: articles
    • Custom Pages: pages
  • Type: single_line_text_field
Was this article helpful to you?