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?
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.
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.
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
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
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?
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.