Metafields and Product Reviews

Plan: Developer Foundations

Lesson 17 of 21 · 30 min

In this lesson, you will learn to add a metafield to a product, GET metafields by product ID, and understand the use cases for metafields. You’ll also learn how to create and GET a product review.

So why do we use metafields?

Metafields allow a developer to set up key and value pairs to store data against a resource, like a product. The data does not appear in the storefront or the control panel by default, but can be surfaced on the storefront depending on permissions and use of GraphQL. This is useful for when information needs to be passed back and forth between an app and the store. Metafields can be added to variants, products, categories, and brands. It is another way of allowing you to tag a product with additional data; acting as an advanced custom field in a way.

Create a Product Metafield

POST /catalog/products/{product_id}/metafields

Creates a product metafield.

Required Fields

  • permission_set (Determines the visibility and writeability of the field by other API consumers.)
    • app_only - Private to the app that owns the field
    • read - Visible to other API consumers
    • write - Open for reading and writing by other API consumers
    • read_and_sf_access - Visible to other API consumers, including on storefront
    • write_and_sf_access - Open for reading and writing by other API consumers, including on storefront
  • namespace - Namespace for the metafield, for organizational purposes. This is set by the developer.
  • key - The name of the field, for example: location_id, color.
  • value - The value of the field, for example: 1, blue.

Use this same endpoint to GET all product metafields.

Example Request: Create a Product Metafield

Example Response: Create a Product Metafield

Using the GraphQL attribute in frontmatter is the simplest way to include product data in your Stencil storefront.

Update a Product Metafield

PUT /catalog/products/{product_id}/metafields/{metafield_id}

Updates a product metafield.

Use this same endpoint to GET and/or DELETE a product metafield.

Product Variant Metafields

POST /catalog/products/{product_id}/variants/{variant_id}/metafields

Creates a product variant metafield.

Required Fields:

  • permission_set
  • namespace
  • key
  • value

Use this same endpoint to GET Product variant metafields.

Example Request Body:

Variant metafields

Example Request: Variant Metafields

Update Product Variant Metafields

PUT /catalog/products/{product_id}/variants/{variant_id}/metafields/{metafield_id}

Updates a product variant metafield.

Use this same endpoint to GET and/or DELETE a variant metafield.

Create a Brand Metafield

POST /catalog/brands/\{brand_id\}/metafieldsCreates a brand metafield.

Required Fields:

  • permission_set
  • namespace
  • key
  • value

Use this same endpoint to GET brand metafields.

Update a Brand Metafield

PUT /catalog/brands/{brand_id}/metafields/{metafield_id}

Updates a brand metafield.

Use this same endpoint to GET and/or DELETE a brand metafield.

Create a Category Metafield

POST /catalog/categories/{category_id}/metafields

Creates a category metafield.

Use this same endpoint to GET category metafields.

Update a Category Metafield

PUT /catalog/categories/{category_id}/metafields/{metafield_id}

Updates a category metafield.

Use this same endpoint to GET and/or DELETE a category metafield.

What about Product Reviews?

A product review contains ratings and feedback from shoppers who have purchased a product. Reviews are displayed on product pages. Reviews cannot be created in the control panel, but they can be created via API. Creating them via API is useful if you are migrating to BigCommerce from another platform and do not want to lose existing reviews. While product reviews are a native platform feature, they can be turned off in favor of a custom setup.

GET Product Reviews

GET /catalog/products/{product_id}/reviews

Returns a list of all product reviews.

Example Response:

GET product reviews

Example Response: GET Product Reviews

Create a Product Review

POST /catalog/products/{product_id}/reviews

Creates a product review.

Required Fields:

  • title
  • date_reviewed

Example Request: Create a Product Review

Example Response: Create a Product Review

Update a Product Review

PUT /catalog/products/{product_id}/reviews/{review_id}

Updates a product review.

Use this same endpoint to GET and/or DELETE a product review.

Resources