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

Topic summary

A developer is encountering a syntax error when attempting to bulk update inventory quantities for multiple product variants using Shopify’s GraphQL Admin API mutation productVariantsBulkUpdate.

Error Details:

  • Receiving syntax error: unexpected COLON (":"), expecting VAR_SIGN at [1, 37]
  • Using PHP cURL for the API call
  • Following official Shopify documentation

Implementation Approach:

  • GraphQL mutation correctly defines variables: $variants and $productId
  • Mutation requests product ID, variant IDs, prices, and user errors in response
  • Variables array includes product GID and array of variant objects with IDs and prices

Current Status:
The issue remains unresolved. The developer is seeking guidance on what might be missing or incorrect in their implementation, particularly regarding the syntax error that suggests a problem with how variables are being passed to the GraphQL mutation.

Summarized with AI on November 1. AI used: claude-sonnet-4-5-20250929.

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!