Anchor to productVariantproduct
productVariant
query
Returns a ProductVariant resource by ID.
Anchor to Possible returnsPossible returns
- Anchor to ProductVariantProduct•
Variant Represents a product variant.
Was this section helpful?
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 query ProductVariantMetafield($namespace: String!, $key: String!, $ownerId: ID!) {6 productVariant(id: $ownerId) {7 linerMaterial: metafield(namespace: $namespace, key: $key) {8 value9 }10 }11 }`,12 {13 variables: {14 "namespace": "my_fields",15 "key": "liner_material",16 "ownerId": "gid://shopify/ProductVariant/43729076"17 },18 },19);2021const data = await response.json();22
query ProductVariantMetafield($namespace: String!, $key: String!, $ownerId: ID!) {
productVariant(id: $ownerId) {
linerMaterial: metafield(namespace: $namespace, key: $key) {
value
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "query ProductVariantMetafield($namespace: String!, $key: String!, $ownerId: ID!) { productVariant(id: $ownerId) { linerMaterial: metafield(namespace: $namespace, key: $key) { value } } }",
"variables": {
"namespace": "my_fields",
"key": "liner_material",
"ownerId": "gid://shopify/ProductVariant/43729076"
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
query ProductVariantMetafield($namespace: String!, $key: String!, $ownerId: ID!) {
productVariant(id: $ownerId) {
linerMaterial: metafield(namespace: $namespace, key: $key) {
value
}
}
}`,
{
variables: {
"namespace": "my_fields",
"key": "liner_material",
"ownerId": "gid://shopify/ProductVariant/43729076"
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `query ProductVariantMetafield($namespace: String!, $key: String!, $ownerId: ID!) {
productVariant(id: $ownerId) {
linerMaterial: metafield(namespace: $namespace, key: $key) {
value
}
}
}`,
"variables": {
"namespace": "my_fields",
"key": "liner_material",
"ownerId": "gid://shopify/ProductVariant/43729076"
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
query ProductVariantMetafield($namespace: String!, $key: String!, $ownerId: ID!) {
productVariant(id: $ownerId) {
linerMaterial: metafield(namespace: $namespace, key: $key) {
value
}
}
}
QUERY
variables = {
"namespace": "my_fields",
"key": "liner_material",
"ownerId": "gid://shopify/ProductVariant/43729076"
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "namespace": "my_fields",3 "key": "liner_material",4 "ownerId": "gid://shopify/ProductVariant/43729076"5}
Response
JSON1{2 "productVariant": {3 "linerMaterial": {4 "value": "synthetic leather"5 }6 }7}