How can I update the quantity for multiple variants of a single product using a GraphQL API mutation

How can I update the quantity for multiple variants of a single product using a GraphQL API mutation

ecsdeveloper2
Tourist
9 1 3

 

We are trying to update product multiple variants stock/quantity using GraphQL Admin API and we are follow the instruction from Shopify docs (https://shopify.dev/docs/api/admin-graphql/2025-01/mutations/productVariantsBulkUpdate) but it is not working and it is returning below error

{"errors":[{"message":"syntax error, unexpected COLON (\":\"), expecting VAR_SIGN at [1, 37]","locations":[{"line":1,"column":37}]}]}

 We are using PHP cURL and here code

$query = <<<QUERY
mutation productVariantsBulkUpdate($variants: [ProductVariantsBulkInput!]!, $productId: ID!) {
productVariantsBulkUpdate(variants: $variants, productId: $productId) {
product {
id
}
productVariants {
id
price
}
userErrors {
code
field
message
}
}
}
QUERY;

$variants = [
"productId" => "gid://shopify/Product/7128034803775",
"variants" => [["id"=>"gid://shopify/ProductVariant/40003114434623", "price"=>"12.00"],
["id"=>"gid://shopify/ProductVariant/40012127830079", "price"=>"6.00"]],
];

Can you please guide me. what is missing/wrong

 

Thanks!

Replies 0 (0)