GraphQL Admin API productVariantsBulkUpdate (mutation) not allow to update inventoryQuantity

GraphQL Admin API productVariantsBulkUpdate (mutation) not allow to update inventoryQuantity

ecsdeveloper2
Tourist
9 1 2

We are trying to update multiple variants inventoryQuantity for single product but it is showing error : 

 

{
field: [ 'variants', '0', 'inventoryQuantities' ],
message: 'Inventory quantities can only be provided during create. To update inventory for existing variants, use inventoryAdjustQuantities.'

}

 

Our script is below

// GraphQL mutation for bulk updating variants
const BULK_UPDATE_VARIANTS = gql`
  mutation productVariantsBulkUpdate($productId: ID!,$variants: [ProductVariantsBulkInput!]!) {
    productVariantsBulkUpdate(productId: $productId, variants: $variants) {
         product {
        id
        variants(first: 10) {
          edges {
            node {
              id
              inventoryQuantity
            }
          }
        }
      }
      userErrors {
        field
        message
      }
    }
  }
`;

async function updateVariantQuantities() {
  try {
    // Example variants to update - replace with your actual variant IDs and quantities
    const productId = "gid://shopify/Product/7128034803775";
    const variants = [
      {
        id: "gid://shopify/ProductVariant/40003114434623",
        inventoryQuantities: {
          availableQuantity: 10,
          locationId: "gid://shopify/Location/36532813887"
        }
      },
      {
        id: "gid://shopify/ProductVariant/40012127830079",
        inventoryQuantities: {
          availableQuantity: 15,
          locationId: "gid://shopify/Location/36532813887"
        }
      }
    ];

 

 

Replies 0 (0)