Querying inventory levels adjusting with Python

Jarvis_
Shopify Partner
1 0 0

Hi,

 

Sorry if the subject is unclear. To preface, I'm completely new to Shopify development and Graphql. I have a bit of experience in Python but not loads.

 

My aim is to use Shopify's API to search by barcode, identify the quantity level, and adjust by a certain number. If the new stock level is now equal to 0, I want to change the product status to draft. 

 

Now I've spent a couple of days on this and I don't seem to be getting very far, I've managed to search by barcode, but that's about it. 

 

I'm not asking for a solution, I'm just asking for a starting point and whether or not this problem is (relatively) easy to solve.

 

Thank you

Reply 1 (1)

Liam
Shopify Staff
2731 298 769

Hi Jarvis,

 

Great to hear you've at least been able to search by barcode - I think the next steps here would be to have the ability to check inventory quantity levels for the products returned by your search. Inventory on Shopify is based on variants, you'll need to fetch the product variant associated with the barcode, and then fetch the inventory item associated with that variant.

 

Once you have the variant quantity, you'll likely want to use the inventoryAdjustQuantities mutation to adjust the item quantity by a specific number. For the action that will set the product status to draft if the new stock level is now equal to 0, you'd likely use the productUpdate
mutation. 

 

I hope this is enough of a starting point for now - let me know if you run into any issues. 

Liam | Developer Advocate @ 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