What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

Re: Bulk update absolute avaiable inventory

Bulk update absolute avaiable inventory

Planche95
Shopify Partner
4 0 1

Hi,

 

I have to update available quantity for 10.000 products via API by settingup absolute values, how can I do it? I notice there is POST call for that, but it updates only one product at time. In GraphGl I can only see mutation "inventorySetOnHandQuantities" to update on Hand quantities.

 

Any ideas?

Replies 2 (2)

magecomp
Shopify Partner
451 31 47

You can use the Shopify GraphQL Admin API to update the available quantity for multiple products at once by using a bulk mutation. Here's an example mutation that you can modify to suit your needs:

 

 

mutation {
  productBulkUpdate(
    productBulkInput: [
      { id: "gid://shopify/Product/1", variants: { inventoryQuantities: [{ locationId: "gid://shopify/Location/1", availableQuantity: 100 }] } },
      { id: "gid://shopify/Product/2", variants: { inventoryQuantities: [{ locationId: "gid://shopify/Location/1", availableQuantity: 200 }] } },
      { id: "gid://shopify/Product/3", variants: { inventoryQuantities: [{ locationId: "gid://shopify/Location/1", availableQuantity: 300 }] } }
      # add more products here
    ]
  ) {
    bulkOperation {
      id
      status
      url
    }
    userErrors {
      field
      message
    }
  }
}

 

 

In this example, we're using the productBulkUpdate mutation to update the available quantity for three products by setting their inventoryQuantities. You can add more products to the productBulkInput array by following the same format.

Note that you will need to replace the product IDs (gid://shopify/Product/1, gid://shopify/Product/2, etc.) with the actual IDs of your products, and the location ID (gid://shopify/Location/1) with the ID of the location where you want to update the inventory.

Once you have the mutation ready, you can execute it using the Shopify GraphQL Admin API.

The API will return a bulkOperation object that includes the ID, status, and URL of the bulk operation. You can use the URL to check the status of the operation and retrieve the results.

 
Helping voluntarily. Please like and accept the solution if it helps. Thanks!
Our Bestseller Shopify Apps    |      Mobile App Builder by MageComp    |      Shoplock Hide Pages/Collections

Need a developer?  Just visit MageComp website
Planche95
Shopify Partner
4 0 1

thanks, but I cant find information about "productBulkUpdate" operation and scheme you used here, only "bulkOperationRunMutation" https://shopify.dev/docs/api/usage/bulk-operations/imports If you mean using "productUpdate" https://shopify.dev/docs/api/admin-graphql/2023-04/mutations/productupdate , it would be good but it deletes all variants not included in product request which is an issue for me