Shopify Flow & Inventory: Auto-Adjusting Stock for External POS Orders
Hey everyone,
As a Shopify migration expert and someone who spends a lot of time diving into the community forums, I often see recurring themes. One of the big ones? Inventory management, especially when you're juggling orders from multiple sales channels or integrating with third-party systems like a physical POS. It's a common headache, and thankfully, Shopify Flow often comes to the rescue.
I recently stumbled upon a really insightful thread started by mstaplet87 that perfectly illustrates a specific challenge and its elegant solution. It's one of those "I found the answer once I finally bit the bullet and posted here" situations, which is exactly why our community is so valuable!
The Multi-Channel Inventory Conundrum
mstaplet87 was facing a familiar scenario: orders coming into Shopify from a third-party POS system (in this case, Clover). The tricky part was that these orders represented in-store purchases where the customer walked out with the product. So, while the order needed to be in Shopify, it didn't require traditional fulfillment. They had set up a Shopify Flow to automatically mark these orders as fulfilled, which is a great start. However, they quickly realized that simply marking an order as fulfilled doesn't always automatically reduce your inventory levels, especially when those orders originate externally.
This is a crucial distinction. Shopify's "Mark a fulfillment order as fulfilled" action primarily updates the fulfillment status of the order. While it often triggers inventory adjustments for standard Shopify orders, external integrations can sometimes bypass or misinterpret these triggers, leaving your inventory counts out of sync. And trust me, nothing is more frustrating than thinking you have stock only to find out it's long gone!
Unlocking Inventory Control with the Admin API Request
To bridge this gap, mstaplet87 correctly identified the solution: using the Admin API Request action within Shopify Flow to directly interact with Shopify's inventory system. Specifically, they were targeting the inventoryAdjustQuantities mutation. This powerful tool allows you to programmatically adjust inventory levels for specific items at specific locations.
The initial attempt, however, hit a snag. The Flow was throwing an "Exception: Mutation input evaluated to invalid JSON. Please ensure the input forms valid JSON after Liquid code is run." error. This is where the community aspect, even if it was a self-solve, really shines. These JSON errors are incredibly common when working with API calls in Flow, and they usually boil down to a couple of subtle syntax issues.
The "Aha!" Moment: Fixing Those Pesky JSON Syntax Errors
After a bit of troubleshooting, mstaplet87 pinpointed two common culprits that many of us have fallen victim to:
deltaas a string vs. a number: In the original problematic code, thedeltavalue was wrapped in quotes:"delta": "-{{lineItemsForeachitem.totalQuantity}}". TheinventoryAdjustQuantitiesmutation expectsdeltato be an integer (a number), not a string. Removing those quotes was key.- The Trailing Comma: Another classic JSON mistake! The original code had a comma after the last key-value pair in the
changesarray's object:"locationId": "gid://shopify/Location/77014401211",. JSON doesn't allow a trailing comma after the last element in an array or object.
Once these small but critical errors were corrected, the API call ran successfully. Here's what the working JSON payload looked like:
{
"input": {
"reason": "correction",
"name": "available",
"changes": [
{
"delta": -{{lineItemsForeachitem.totalQuantity}},
"inventoryItemId": "{{lineItemsForeachitem.inventoryItemId}}",
"locationId": "gid://shopify/Location/77014401211"
}
]
}
}
Step-by-Step: Setting Up Your Shopify Flow for Inventory Adjustment
Ready to implement this solution for your own store? Here’s how you can set up a Shopify Flow to automatically reduce inventory for external orders:
-
Start a New Flow:
- Go to your Shopify admin, navigate to Apps > Shopify Flow.
- Click Create flow.
- Choose a trigger. For orders coming from an external POS that need inventory adjusted, Order created is usually the best starting point.
-
Add Conditions (Optional but Recommended):
- If you only want this inventory adjustment to apply to specific types of orders (e.g., only those from your POS channel), add a condition like "Order > Sales channel is > POS" or "Order > Tags > includes > pos_order". This prevents unintended inventory reductions for your regular online orders.
-
Action: Mark Fulfillment Order as Fulfilled (If Applicable):
- If your goal is also to mark these orders as fulfilled without creating a fulfillment, add the action Mark a fulfillment order as fulfilled. Remember, as we discussed, this alone won't handle inventory for external orders.
-
Action: For Each "line item":
- Drag and drop the For each action.
- Select Order > Line items. This ensures that you iterate through every product in the order to adjust its specific inventory.
-
Inside the Loop: Admin API Request for
inventoryAdjustQuantities:- Within the "For each" loop, add the Admin API Request action.
- Set the API action to Run GraphQL.
- In the GraphQL query box, paste the following GraphQL mutation definition:
mutation inventoryAdjustQuantities($input: InventoryAdjustQuantitiesInput!) { inventoryAdjustQuantities(input: $input) { userErrors { field message } } } - In the Variables box (this is where the dynamic Liquid magic happens), paste the following JSON payload:
{ "input": { "reason": "correction", "name": "available", "changes": [ { "delta": -{{lineItemsForeachitem.totalQuantity}}, "inventoryItemId": "{{lineItemsForeachitem.inventoryItemId}}", "locationId": "gid://shopify/Location/77014401211" } ] } }Important Note on
locationId: The"gid://shopify/Location/77014401211"value is specific to mstaplet87's store. You'll need to replace this with your own location ID. You can find your location ID by going to Settings > Locations in your Shopify admin. Click on a location, and its ID will be in the URL (e.g.,.../locations/YOUR_LOCATION_ID). Then prependgid://shopify/Location/to it.
-
Test Your Flow:
- Crucial step! Always test your Flow thoroughly. Use a test order or a draft order to ensure it runs as expected without negatively impacting your live inventory. Watch for any errors in the Flow run history.
Final Thoughts on Keeping Your Stock Tidy
Integrating external systems with Shopify can be a bit of a dance, especially when inventory is involved. What mstaplet87's journey highlights is the incredible power of Shopify Flow combined with the Admin API. It gives you granular control over your store's operations, allowing you to tailor solutions to even the most specific business needs. The key takeaways here are understanding the nuances of inventory actions and being meticulous with your JSON syntax. A misplaced quote or a trailing comma can derail an otherwise perfect automation.
Don't hesitate to lean on the Shopify community when you hit these kinds of snags. Chances are, someone else has faced a similar challenge, and sharing your insights (even if you find the answer yourself, like mstaplet87 did!) makes the platform better for everyone. Accurate inventory is the backbone of any successful retail business, and with tools like Flow, you're well-equipped to keep it precise across all your channels.