Update Product Variant input as SKU in GraphQL

Update Product Variant input as SKU in GraphQL

srilekha
Shopify Partner
3 0 0

Hi,

 

How to update product variant by providing "SKU" or "handle" under "input" instead of providing "id" as input using GraphQL

 

The below code is not working:

 

 

mutation {
  productVariantUpdate(
    input: {
      sku: "test123",
      handle: "summer-dress"
      price: "18.99"
  }
 )
 {
    productVariant {
      id
      price
      sku
    }
  }
}

 

 

 

 

Replies 4 (4)

hanvari
Shopify Partner
2 0 0

Hi,

 

I see this is a relatively old post with no response. Have you had any luck figuring out how to do this? 
I'm facing the same issue right now (using `productVariantUpdate` using SKU to identify the variant).


Thanks

shivam2238
Shopify Partner
1 0 0

Hi,
Did you figure out using SKU as a product input?

haydenl
Shopify Partner
1 0 0

Hi,

I have managed to do this using version 2024-07 and passing the sku through inventoryItem.

 

 

mutation UpdateProductVariant($input: ProductVariantInput!) {
    productVariantUpdate(input: $input) {
        productVariant {
            id
        }
        userErrors {
            field
            message
        }
    }
}



{
    "input": {
        "id": "gid://shopify/ProductVariant/45499072184555",
        "price": 4.99,
        "inventoryItem": {
            "sku": "SKU001"
        }
    }
}

 

 

swotcheltissick
Shopify Partner
1 0 0

You're passing the "id"! The question was how do you update it with just the sku.