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 multiple product variant fields
- Update non-existing product variant
- productVariantUpdate reference
Examples
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",
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-04/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
JSON{
"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
JSON{
"productVariantUpdate": {
"productVariant": {
"id": "gid://shopify/ProductVariant/43729076",
"metafields": {
"edges": [
{
"node": {
"id": "gid://shopify/Metafield/1069228993",
"namespace": "my_fields",
"key": "sole_material",
"value": "Rubber"
}
},
{
"node": {
"id": "gid://shopify/Metafield/1069228994",
"namespace": "my_field",
"key": "liner_material",
"value": "Synthetic Leather"
}
}
]
}
},
"userErrors": []