How can I edit the SKU of a variant using GraphQL?

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

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
    }
  }
}

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

1 Like

Quick and accurate response. Thank you very much.