Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Update Stock of variants in bulk through graphql api

Update Stock of variants in bulk through graphql api

Tayyab_sheikh
Shopify Partner
2 0 1

def update_product_variant_query(key)
<<~QUERY
mutation {
bulkOperationRunMutation(
mutation: "mutation call($input: ProductVariantInput!) {productVariantUpdate(input: $input) {
productVariant {
id
price
sku
}
userErrors {
field
message
}
}
}",
stagedUploadPath: "#{key}") {
bulkOperation {
id
url
status
}
userErrors {
message
field
}
}
}
QUERY
end
I am updating price of variants through this graphl ql api. But when I tried to update stock(inventoryQuantity) of variants through this same api query I am recieving error. So please tell me how can update quantity of stock (inventoryQuantity) in bulk through graphql api

Reply 1 (1)

Shayne
Shopify Staff (Retired)
254 20 48

You can't write inventory directly to variants, because we don't know which locations the inventory should be allocated to. Managing inventory isn't really on the variant, the inventoryQuantity is a convenience field that's a rolled-up version of the existing quantities at the stocked locations.

Instead, use the inventoryBulkAdjustQuantityAtLocation mutation to change the inventory quantity of a specific inventory item.

Shayne | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog