Skip to content
  • There are no suggestions because the search field is empty.

Pulling Product Metafield Data into an Experience

You can now access product metafields directly through the Visually SDK using the visually.sdk_api.getProductsMetafields method. This allows you to retrieve metafield values for specific products and use them in your experiences.

Method

visually.sdk_api.getProductsMetafields(handles: string[], metafields: MetafieldRequest[])

Interface

interface MetafieldRequest {
  namespace: string;
  keys: string[];
}

This method returns the products along with their metafields. If a metafield is not returned, it means it wasn’t synced.

Sync Metafields in Visually

Before you can retrieve a metafield via the SDK, it must be synced in Visually.

  1. Open your Visually dashboard.

  2. Go to Global RulesProduct Metafields section.

  3. Click Add New Metafield.

  4. Enter the metafield information exactly as it appears in Shopify:

    • Namespace: custom

    • Key: size_and_height


After adding a new matfield, head to your Account Settings to sync the catalog.

Once metafields are synced, you can retrieve them using the SDK method.

Example

visually.sdk_api.getProductsMetafields(
  ["medium-soft-ruled-journal-charcoal"],
  [
    {
      namespace: "jasper",
      keys: ["FFSS", "FFSS_Discount"],
    }
  ]
);

Tips for Avoiding Common Issues

  • Always enter namespace and key separately in Visually.

  • Make sure the metafield exists and is populated in Shopify.

  • Sync any new metafields before attempting to fetch them via the SDK.