i have written a little server-run python tool that will simply read an excel file with stock levels and updates the onHand levels of those products using the GraphQL API.
However it suddendly stopped working for one my shops, throwing below error for all update items:
{
‘field’: [‘input’, ‘setQuantities’, ‘123’, ‘inventoryItemId’],
‘message’: ‘The specified inventory item is not allowed to be adjusted via API.’
}
My other shop is updating just fine, the only thing i changed for the broken one was installing and using the bundles app. I noticed these bundles would also appear in the products export. Could this app be the cause?
Alos any guidance on how to further troubleshoot these errors would be great, found nothing that would let me dig deeper on the cause of that error.
It’s possible that the Bundles app may be affecting your inventory adjustments, especially if it’s managing inventory levels for bundled items. If the app has some sort of control over the inventory of those items, it might be preventing other APIs from making adjustments.
In terms of troubleshooting, here are a few suggestions:
Check the inventory item ID: Make sure the inventoryItemId you are trying to update is correct. You can retrieve the inventory item ID by querying the ProductVariant object using the GraphQL API.
Check permissions: Make sure your API key has the permissions to adjust inventory levels.
Try adjusting inventory manually: Try adjusting the inventory level of the problematic items manually in Shopify admin to see if it’s possible. If it’s not, then the issue might be with the Bundles app.
Check if item is tracked: Ensure that the item you are trying to update is tracked. You can’t adjust the inventory level of an item that isn’t tracked.
Thanks for your suggestions, i have checked for them.
Also i like to add, that NONE of my inventory items are being updated, I only get error messages back, not a single inventory change return.
Check the inventory item ID:
They have to be correct, I am retrieving those from Shopify. My app pulls all stock levels for every variant in a bulk query as below. Then it looks it by SKU or Barcode in a provided stock level file and then creates an update payload with those inventoryitemIds. As i said, it worked before.
bulkOperationRunQuery(
query:"""
{
productVariants{
edges {
cursor
node {
id
barcode
sku
inventoryItem {
inventoryLevel(locationId: $location_id) {
id
available
quantities(names: ["available", "on_hand", "committed"]) {
name
quantity
}
}
}
}
}
}
}
Check Permission:
My app has these permissions: write_inventory, read_inventory, write_products,read_products.
Try adjusting inventory manually:
I did that from the Backend and there was no problem! even with a bundle item.
Yes, all items are tracked (shopify) and have been before.
My last resort would be to uninstall the bundle app, but this will likely remove all the created bundles. However i saw the bundles appear in the product export csv. Would this be a way to back them up and restore for testing if its the bundles app?
Thank you for your suggestion, that is actually the cleanest way currently I think, as I dont see any other way to query the property of an inventoryitem’s API-mutability.
In addition to Erik_lindberg Solution:
The reason why I ran into this problem is due to the logic of my Stock update code.
It looks up all products by their SKU in the stock update file, if the SKU is not found in this file then that inventorylevel will be set to 0. This way I ensure that products that are not included in the update file anymore (due to discontinuation or similar) will not show an incorrect stock level as they wouldnt get updated anymore.
Bundles present a special case when following this logic. In my case they were created without a SKU, but even if they were given one, it wouldnt be found in the update file. But they also are associated with an InventoryItemId and Level, so they are returned by quering all Variants Inventorylevels and thus my code willt try to set them to 0. Since the stock level of bundles is automatically calculated by the lowest amount available for a product in a bundle it makes sense of course those stock levels can’t be altered by any other means and that is what threw this error at me.
So basically there is the need for a check wheter or not an items inventoryLevel is actually mutable or not. Erik’s solution accounts for that, but It would be great if it was possible to query that mutable/non-mutable property of an InventoryItem so there is no need to manually add a filter.
I couldnt find any hint of that in the Grapqhl Documentation.
EDIT:
Just found the “requiresComponents” field of the ProductVariant object:
“Whether a product variant requires components. The default value is false. If true, then the product variant can only be purchased as a parent bundle with components and it will be omitted from channels that don’t support bundles.”
Assuming that requireComponents is only true for bundles and that all bundles variants inventory levels are always immutable then this would be the check i need. But maybe there are other cases the logic would break.