productVariantUpdate not update the quantity of my variant

I would like to update quantity of single variant with the graphql .
I understand that I can’t use just the variant id to do this, how can I do this if I only have the variant id and the product id and the locations ?

I have now tried to use productVariantUpdate but it is not updating the quantity .
whereas with productUpdate I update the product but if I don’t specify the variants it deletes them right?

Hi Leobar00,

You’re correct in saying that the productVariantUpdate mutation doesn’t directly update the inventory quantity. Instead, you need to use the inventoryQuantityAdjust or inventoryQuantitySet mutation to adjust or set the inventory quantity of a variant.

Here’s an example of how you can use inventoryQuantityAdjust mutation:

mutation {
  inventoryQuantityAdjust(input: {
    inventoryLevelId: "gid://shopify/InventoryLevel/123456789",
    availableDelta: 10
  }) {
    inventoryLevel {
      id
      available
    }
    userErrors {
      field
      message
    }
  }
}

In this mutation, inventoryLevelId is the ID of the inventory level that you want to adjust, and availableDelta is the number by which you want to adjust the available inventory quantity.

And yes, you’re correct about the productUpdate mutation as well. If you update a product and only include some variants in the update, then any variants not included will be deleted. To safely manage variants without the risk of deleting excluded variants, you can use productVariantsBulkUpdate.

Here’s how you can use productVariantsBulkUpdate:

mutation {
  productVariantsBulkUpdate(variants: [{ id: "gid://shopify/ProductVariant/1234567890", price: "10.00" }]) {
    productVariants {
      id
      price
    }
    userErrors {
      field
      message
    }
  }
}

In this mutation, you will need to pass in the variant id and the updated price. You can replace the price field with any other field you want to update.

Hope this helps!

1 Like

Thanks @Liam ,
what is the best way to update product quantities by having the id of the product, variant and inventoryItem ?
I am passed the total quantity in the inventory so the delta would require calculations that I would rather not do .
Thank you very much for your support

@Liam I cannot find the inventoryQuantitySet you mentioned in the previous answer could you send me the link to the documentation ? Thanks

Hi again Leobar00,

The best way to update product quantities with the data you have could be to use the /inventory_levels/set.json endpoint. If you ever need to adjust the inventory by a delta (increase or decrease), you can use the adjust endpoint: /admin/api/2023-07/inventory_levels/adjust.json

More info on these from our dev docs here.

Thanks @Liam ,
I use the graphql API , and i would like to update only available field of quantity .
so that those in the orders are not counted and only those available are updated,:
which mutation for graphql should I use?

@Liam with productVariantsBulkUpdate mutation can i update the quantities of a variant ?

Hi Liam. I’m hoping you can elaborate on this: productVariantUpdate, though it accepts inventoryQuantities input, does not actually update the inventory quantity? May I ask what the reasoning is for this? It’s very confusing behavior as the GraphQL input is accepted but seems to silently fail to adjust the quantity. At the very least it would be helpful if the mutation returned an error or warning if inventoryQuantities was passed in.

1 Like