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.
Metafield Sync Setup
To use this method, the metafields must first be synced.
A new section is available under the Global Rules area, where you can add the namespaces and keys for the metafields you would like to sync.
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"],
}
]
);