A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I have a problem when trying to update the SKU value of a variant. I am trying to update it using productVariantUpdate, but the "sku" field is not defined in productVariantInput.
Has anyone encountered this issue?
Thanks,
Albert
Solved! Go to the solution
This is an accepted solution.
Hi, there
The sku field is in the InventoryItem .you could refer to this
mutation UpdateProductVariantSKU {
productVariantUpdate(input: {
id: "gid://shopify/ProductVariant/xxxxxx",
inventoryItem: {
sku: "xxxxxxxxx"
}
}) {
productVariant {
id
sku
}
userErrors {
field
message
}
}
}
https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/productVariantUpdate
try something like that:
mutation VariantUpdate($input: ProductVariantInput!) {
productVariantUpdate(input: $input) {
productVariant {
id
sku
}
userErrors {
field
message
}
}
}
Hi @alb3rts
Like this,
mutation {
productVariantUpdate(input: {id: "gid://shopify/ProductVariant/43729076", position: 1, barcode: "1234", weight: 1.5, weightUnit: KILOGRAMS, requiresShipping: true, sku: "EXAMPLE_SKU", taxable: true, taxCode: "", options: ["M"], inventoryItem: {cost: 19.99}}) {
productVariant {
id
legacyResourceId
sku
barcode
weight
weightUnit
inventoryItem {
id
legacyResourceId
requiresShipping
unitCost {
amount
}
}
position
selectedOptions {
name
value
}
product {
id
title
legacyResourceId
}
}
userErrors {
field
message
}
}
}
This is an accepted solution.
Hi, there
The sku field is in the InventoryItem .you could refer to this
mutation UpdateProductVariantSKU {
productVariantUpdate(input: {
id: "gid://shopify/ProductVariant/xxxxxx",
inventoryItem: {
sku: "xxxxxxxxx"
}
}) {
productVariant {
id
sku
}
userErrors {
field
message
}
}
}
https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/productVariantUpdate
Quick and accurate response. Thank you very much.