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.

Auto Trigger Product status update to draft/active if inventory level adjusted to 0/5 quantity

Auto Trigger Product status update to draft/active if inventory level adjusted to 0/5 quantity

Morshed_DLD
Visitor
2 0 1

Is there any option to achieve "Trigger product status to draft or active on inventory level update to zero or greater" ?

I'm using admin rest API in desktop app. In my shopify store i have large number of products(more than 20k). i have more than 20 physical store too so my physical inventory is constantly changing as i'm selling same product offline and online. Therefore everyday i  need to update inventory level if i have any sales online of offline.

 

As i described above 20k products are too much time consuming to update and if any items stock goes 0 i want the product status to be updated automatically depending on the quantity update. If i try to update status via API it will also be another time consuming task.  a single API call won't  update both of the things hence it's a big issue. please suggest me if shopify itself take some initiative to achieve this kind of issue or i can do anything else?   

 

FYI: I don't want to update it by CSV upload.

 

Reply 1 (1)

mics
Trailblazer
172 12 34

Yes, it is possible to trigger a product's status to draft or active based on the inventory level using Shopify's webhooks.

You can create a webhook that listens for the inventory_levels/update event. This event is triggered when the inventory level of a product is updated. In the webhook payload, you can check the new inventory level of the product and update its status accordingly.

To update the status of a product using the Shopify API, you can use the PUT /admin/api/2021-07/products/#{product_id}.json endpoint. In the request body, you can set the status parameter to either "draft" or "active" depending on the inventory level.

Here's an example of how you can implement this:

  1. Create a webhook in your Shopify store that listens for the inventory_levels/update event. The webhook should send a POST request to a URL in your desktop app that handles the webhook payload.

  2. In your desktop app, create a route that handles the webhook payload. In the route handler, extract the product ID and the new inventory level from the payload.

  3. Use the Shopify API to get the current inventory level of the product using the GET /admin/api/2021-07/products/#{product_id}.json endpoint.

  4. Compare the new inventory level with the current inventory level. If the new inventory level is greater than zero and the product status is "draft", update the product status to "active". If the new inventory level is zero and the product status is "active", update the product status to "draft".

  5. Use the Shopify API to update the product status using the PUT /admin/api/2021-07/products/#{product_id}.json endpoint.

By using this method, the product's status will be automatically updated based on the inventory level, and you won't have to manually update the status or inventory level for each product.

banned