A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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?
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.
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