'Shopify Inventory Not Update via Shopify GraphiQL App

I have checked the Shopify GraphQL API, and I have tried to update the product inventory on Shopify but when I execute the graphql API it says "

Inventory quantities cannot be updated with variants API

The mutation I am trying to run:

mutation productVariantsBulkUpdate(
  $productId: ID!,
  $variants [ProductVariantsBulkInput!]!
) {
    productVariantsBulkUpdate(
      productId: $productId,
      variants: $variants
    ) {
      product {
        id
      }
      productVariants {
        id
      }
      userErrors {
        field
        message
      }
    }
}

And the variable of this request

{"variants": {"inventoryQuantities": {"availableQuantity": 10,"locationId":"gid://shopify/Location/66027421902" },"id":"gid://shopify/ProductVariant/40747448828110" },"productId": "gid://shopify/Product/6899888488654"}

I have checked with the bulk update inventory but it is not what I need, how do I set (not adjust) the inventory level using the Shopify API?



Solution 1:[1]

Unfortunately, it looks like this is intentional and that there is no way to directly set inventory levels using the GraphQL API at this time

From this Shopify documentation page:

There is no mutation to set levels directly using the GraphQL Admin API. Use the adjustInventoryLevelQuantity mutation to adjust the inventory level instead.

The good news is that this is possible via the REST API, and details are provided on the same page as above, under the "REST" tab.


I will request this feature from Shopify as it is useful in some cases where adjusting quantity is not appropriate (e.g. writing idempotent functions).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Josh