[Using Admin API Request] Another way to control the Inventory Quantity

With this new "action" in Shopify Flow, it is now easier for the Shopify merchants to create a flow which requires to make some Admin API calls. In this article, we will use this "action" to control the Inventory Quantity.

Note:

This article is another(probably a better and easy) way to control the inventory quantity(see here for the previous article). We will be using action to Send Admin API request to create our flow.

Another change is the way to represent the problem statement. Thanks to Milan(Shopify Merchant - LinkedIn) for helping me to redraft the content for Context, Problem and Solution sections. It is now more intuitive to understand for merchants and developers.

Let’s start this….

Context:

The merchant is storing inventory at a 3PL warehouse that syncs the inventory quantity to the Shopify store using a backend integration.

Problem:

The merchant is experiencing overselling of variants due to inventory discrepancies in their 3PL platform or incorrect quantity counts at the warehouse.

Solution:

Create a variant buffer quantity to avoid overselling.
For example, if a product variant inventory quantity falls below 7 units, then update it to 0. The exact buffer quantity can be fine tuned over the time.
Use Shopify Flow that triggers when the variant qty is updated and use Admin API action to set the qty of that variant to 0 if the remaining qty is less than 7.

Prerequisites:

Limitations:

This solution is only applicable to items which are stocked at one location.

Implementation:

  1. Create new Flow in the Shopify Flow app.

    Create a new flow in shopify flow application

  2. Select “Product variant inventory quantity changed“ trigger.

    Select “Product variant inventory quantity changed“ trigger from the list

  3. Add condition to check if its the correct variant(we want to apply this flow for only specific variants)

    Find the legacyResourceId field, this will be used to check if its the variant that we want to control its quantity for.

  4. Add the variant id(legacyResourceId)

    Help: Check this article for how to find the variant id.

  5. Follow Step 3 and 4 to add more condition.

  6. Now, we will check if the remaining quantity is below our buffer. We will add new condition with two criteria, One for the Upper limit and the other for checking if it is already 0.

    Add condition to check the remaining inventory quantity

  7. Next, add action to make Admin API request and select “inventorySetOnHandQuantities“ from the list

  8. Change the input so that it looks like the following.
    The valid values for the “reason“ is predefined and can be found here. You can follow this article to find the locationId. The value for field “inventoryId“ can be populated using “Add a variable“ button at the top right corner.

  9. We are done with the setup and we can turn on this workflow by clicking this button. Feel free to set some meaningful name for this workflow 🤓.

In this article I have demonstrated a way to use Admin API request for changing the inventory quantity, We can extend this to all the possible usecases like add/remove tag to a customer or product or anything that is possible with the available GQL APIs via Admin API action.