A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Shopify POS is showing two locations for each product. Headquarters is one and never has inventory, <insert store name here> is the other and is the one we always choose when checking someone out. Can you remove the Headquarters location so we don't tap it by mistake
That's the request that came in to our dev team. When we looked into it, it seems like every product we add via the API automatically gets assigned to the HQ location and then our code adds the store location for whatever store the product is selling at. Each store is near a specific college campus so the goods are usually only sold at the college they are near.
We're using the Python SDK and have tried to delete and destroy the InventoryLevel associated with the HQ location and each variant. We keep getting errors like `HTTP Error 422: Unprocessable Entity`.
We can remove the location manually by browsing to the variant online and using it's Manage locations screen to uncheck the location. We're just trying to automate this process.
What is the correct way to use the API to remove a location from a product? Or if there is a better way for us to be creating these products so they aren't automatically associated with the HQ in the first place, I'd be interested in that as well.
Solved! Go to the solution
This is an accepted solution.
Hey @cspinelive, thanks for reaching out again, this was a great question - I was able to do a little more digging into this and may have a solution for you on an API method to remove a location from a variant. I would suggest starting with a ProductVariant.id
and locationId
, that you know are active on the store. These can be used to return a InventoryLevel.id
with a query like this using GraphQL:
{ productVariant(id: "gid://shopify/ProductVariant/{ID}") { id displayName inventoryItem { id inventoryLevel(locationId: "gid://shopify/Location/{ID}") { id } } } }
InventoryLevel.id
will be formatted as follows: "gid://shopify/InventoryLevel/{ID}?inventory_item_id={ID} and can be used as an input of an inventoryDeactivate mutation, which provides the same functionality as you described via the admin. It is also worth noting that you will need the write_inventory
access scope on the shop to complete the call - I tested this method on my development environment and was able to remove an inventory/fulfillment location from the associated product variant with the above mutation. Alan | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
We seem to be having a similar problem to this person: https://community.shopify.com/c/shopify-apis-and-sdks/cannot-destroy-inventory-level-can-t-fulfill-o...
And I swear we got the .connect(relocate_if_necessary=True) thing to work once, but I guess not because it isn't working anymore.
Hey @cspinelive thanks for getting in touch. We'd recommend reaching out here/making a issue here, which would be the best resource for this issue: https://github.com/Shopify/shopify_python_api
All the best!
Alan | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
To be more specific, forget about the Python SDK for the moment, what is the API equivalent of navigating to a variant, clicking Edit Locations and unchecking the box on one of them?
This is an accepted solution.
Hey @cspinelive, thanks for reaching out again, this was a great question - I was able to do a little more digging into this and may have a solution for you on an API method to remove a location from a variant. I would suggest starting with a ProductVariant.id
and locationId
, that you know are active on the store. These can be used to return a InventoryLevel.id
with a query like this using GraphQL:
{ productVariant(id: "gid://shopify/ProductVariant/{ID}") { id displayName inventoryItem { id inventoryLevel(locationId: "gid://shopify/Location/{ID}") { id } } } }
InventoryLevel.id
will be formatted as follows: "gid://shopify/InventoryLevel/{ID}?inventory_item_id={ID} and can be used as an input of an inventoryDeactivate mutation, which provides the same functionality as you described via the admin. It is also worth noting that you will need the write_inventory
access scope on the shop to complete the call - I tested this method on my development environment and was able to remove an inventory/fulfillment location from the associated product variant with the above mutation. Alan | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog