Returns a ProductVariant resource by ID.


Anchor to id
id
required

The ID of the ProductVariant to return.


Was this section helpful?

Anchor to ProductVariant
ProductVariant
Access requirements

Represents a product variant.


Was this section helpful?

Examples

Hide code
DescriptionCopy
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-10/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();

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)

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"
},
},
});

use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$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]);

Hide code
Input variables
Copy
{
"namespace": "my_fields",
"key": "liner_material",
"ownerId": "gid://shopify/ProductVariant/43729076"
}

Hide code
Response
JSON
{
"productVariant": {
"linerMaterial": {
"value": "synthetic leather"
}
}
}