Anchor to productVariantUpdateproduct
productVariantUpdate
mutationDeprecated
Requires access scope. Also: The user must have a permission to update a product variant.
Updates a product variant. Use instead.
Anchor to Arguments
Arguments
- Anchor to inputinput•Product
Variant requiredInput! The updated properties for the product variant.
Was this section helpful?
Anchor to ProductVariantUpdatePayload returnsProductVariantUpdatePayload returns
- Anchor to productproduct•
The product associated with the variant.
- Anchor to productVariantproduct•
Variant The updated variant.
- Anchor to userErrorsuser•
Errors [UserError!]! non-null The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a new metafield and update another on an existing product variant
- Update a product variant with media
- Update a product variant's price and compare-at price
- Update non-existing product variant
- productVariantUpdate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation updateProductVariantMetafields($input: ProductVariantInput!) {6 productVariantUpdate(input: $input) {7 productVariant {8 id9 metafields(first: 3) {10 edges {11 node {12 id13 namespace14 key15 value16 }17 }18 }19 }20 userErrors {21 message22 field23 }24 }25 }`,26 {27 variables: {28 "input": {29 "metafields": [30 {31 "namespace": "my_field",32 "key": "liner_material",33 "type": "single_line_text_field",34 "value": "Synthetic Leather"35 },36 {37 "id": "gid://shopify/Metafield/1069228993",38 "value": "Rubber"39 }40 ],41 "id": "gid://shopify/ProductVariant/43729076"42 }43 },44 },45);4647const data = await response.json();48
mutation updateProductVariantMetafields($input: ProductVariantInput!) {
productVariantUpdate(input: $input) {
productVariant {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation updateProductVariantMetafields($input: ProductVariantInput!) { productVariantUpdate(input: $input) { productVariant { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }",
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "liner_material",
"type": "single_line_text_field",
"value": "Synthetic Leather"
},
{
"id": "gid://shopify/Metafield/1069228993",
"value": "Rubber"
}
],
"id": "gid://shopify/ProductVariant/43729076"
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation updateProductVariantMetafields($input: ProductVariantInput!) {
productVariantUpdate(input: $input) {
productVariant {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
{
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "liner_material",
"type": "single_line_text_field",
"value": "Synthetic Leather"
},
{
"id": "gid://shopify/Metafield/1069228993",
"value": "Rubber"
}
],
"id": "gid://shopify/ProductVariant/43729076"
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation updateProductVariantMetafields($input: ProductVariantInput!) {
productVariantUpdate(input: $input) {
productVariant {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "liner_material",
"type": "single_line_text_field",
"value": "Synthetic Leather"
},
{
"id": "gid://shopify/Metafield/1069228993",
"value": "Rubber"
}
],
"id": "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
mutation updateProductVariantMetafields($input: ProductVariantInput!) {
productVariantUpdate(input: $input) {
productVariant {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"input": {
"metafields": [{"namespace"=>"my_field", "key"=>"liner_material", "type"=>"single_line_text_field", "value"=>"Synthetic Leather"}, {"id"=>"gid://shopify/Metafield/1069228993", "value"=>"Rubber"}],
"id": "gid://shopify/ProductVariant/43729076"
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "input": {3 "metafields": [4 {5 "namespace": "my_field",6 "key": "liner_material",7 "type": "single_line_text_field",8 "value": "Synthetic Leather"9 },10 {11 "id": "gid://shopify/Metafield/1069228993",12 "value": "Rubber"13 }14 ],15 "id": "gid://shopify/ProductVariant/43729076"16 }17}
Response
JSON1{2 "productVariantUpdate": {3 "productVariant": {4 "id": "gid://shopify/ProductVariant/43729076",5 "metafields": {6 "edges": [7 {8 "node": {9 "id": "gid://shopify/Metafield/1069228993",10 "namespace": "my_fields",11 "key": "sole_material",12 "value": "Rubber"13 }14 },15 {16 "node": {17 "id": "gid://shopify/Metafield/1069228994",18 "namespace": "my_field",19 "key": "liner_material",20 "value": "Synthetic Leather"21 }22 }23 ]24 }25 },26 "userErrors": []27 }28}