Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I need to get a products variant metafield and i am able to get the metafield using the admin graphql api but not using the storefront api this needs to take in a product variant id as an argument
Solved! Go to the solution
This is an accepted solution.
that does not work for the storefront api
const query = `
{
node(id: "${variantId}") {
... on ProductVariant {
id
title
metafield(key: "buyout_price", namespace: "product_page") {
value
id
}
}
}
}
`;
got it though
, it seems that you are trying to retrieve a specific metafield for a product variant using its key and namespace. However, the metafield query for the Storefront API requires the id of the metafield instead.
Here is an example query that should work for you:
{
productVariant(id: "gid://shopify/ProductVariant/{variant-id}") {
id
title
metafields(first: 5) {
edges {
node {
id
key
namespace
value
}
}
}
}
}
This query should return the metafields for the specified product variant, including their id
, key
, namespace
, and value
.
If this fixed your issue, likes and accepting as a solution are highly appreciated.
Build an online presence with our custom built Shopify Theme EcomifyTheme
This is an accepted solution.
that does not work for the storefront api
const query = `
{
node(id: "${variantId}") {
... on ProductVariant {
id
title
metafield(key: "buyout_price", namespace: "product_page") {
value
id
}
}
}
}
`;
got it though