We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

How to add sku to product variant via graphQL

Solved

How to add sku to product variant via graphQL

Iwebaholic
Shopify Partner
2 0 0

I'm using the Shopify GraphiQL App to set up my mutations, and I'm using the GraphQL docs as a reference. The docs say that updating the sku using the productVariantUpdate mutation is deprecated and to use inventoryItem.sku instead, however InventoryItemInput does not have sku as an option and I get a type error when I try to use it in this mutation "InputObject 'InventoryItemInput' doesn't accept argument 'sku'". 

 

Using the deprecated 'sku' value works like this, 

 

 

 

mutation MyMutation {
  productVariantUpdate(
    input: {id: "gid://shopify/ProductVariant/49897690000000", price: "20.45", sku: "test5/20-51s"}
  ) {
    productVariant {
      id
      sku
    }
  }
}

 

 

 

 

But the whole point of updating our application was to get away from deprecated REST API usage, and I can't seem to find a way to update a sku for a product variant using a GraphQL mutation that isn't deprecated as well. 

 

 

Accepted Solution (1)

dmntlr
Tourist
3 1 1

This is an accepted solution.

I had the same problem. Please try to use API version 2024-07. With the newest version you can pass sku in the inventoryItem.

 

View solution in original post

Replies 6 (6)

dmntlr
Tourist
3 1 1

This is an accepted solution.

I had the same problem. Please try to use API version 2024-07. With the newest version you can pass sku in the inventoryItem.

 

Iwebaholic
Shopify Partner
2 0 0

Thank you.

BeeBuzz
Shopify Partner
2 0 0

is it worked ??

 

neological
Visitor
1 0 0

Well, we have the same problem as we use SKUs for product identification in the warehouse. Now with the 2025-01 update can't find a way to save SKUs for new products. Is there any solution to update/add SKU for a product? 

 

Not even the price is saved when productCreate GraphQL.

dmaithonis
Shopify Partner
2 0 0

I'm also trying to update to 2025-01.  Same issue, I have new products without variants that need to have SKUs.  It looks like I need to create a variant and to do that I need to create a variantOption.  All of our existing items still have SKUs without variants/variantOptions, it seems creating new varitant-less products with a SKU is impossible in 2025-01...

jhonatanvillanu
Shopify Partner
1 0 1

With the last version 2025-01 you need to create first the product

 this create a variant option by default get id of this variant.

as a second step to add sku, price you need to update the variant by productVariantsBulkUpdate

https://shopify.dev/docs/api/admin-graphql/latest/mutations/productVariantsBulkUpdate?example=Modify...

```

"variants": [
        {            
           "id": "gid://shopify/ProductVariant/50796440158513",
            "price": "500",
            "inventoryItem": {
                "sku": "1234567890"
            }
        }
    ],

```