Shopify Flow & Admin API: Unraveling Inventory Automation Headaches (and a Surprising Solution!)
Hey store owners and fellow Shopify enthusiasts!
Automating inventory management is often high on the wishlist for many of us. Imagine a world where your stock levels magically replenish themselves when they hit a certain threshold. Sounds like a dream, right? Well, one of our community members, ssg1205, embarked on this very quest, trying to leverage Shopify Flow and the Admin API to make it a reality. Their journey, shared on the Shopify community forums, offers some fantastic insights into common pitfalls and clever workarounds.
The Core Challenge: Shopify Flow and API Mutations
ssg1205 was trying to use Shopify Flow's 'Send Admin API request' action to update inventory quantities using the inventorySetQuantities or inventoryAdjustQuantities GraphQL mutations. The idea was simple: when an order came in, Flow would check stock, and if a product fell below a certain level, it would trigger a replenishment.
However, they kept running into a brick wall. Despite the Flow 'Run code' step succeeding, the 'Send Admin API request' step consistently failed with two key messages:
Exception: Mutation had errors: "Variable $input of type InventorySetQuantitiesInput! was provided invalid value"Output: No data returned. This is expected for this action(which, while expected for the output, meant the mutation itself wasn't going through).
This error, "Variable $input was provided invalid value," is a classic sign that the API isn't happy with the structure or content of the data you're sending. Here's a look at one of the problematic inputs ssg1205 shared:
{
"mutation_name": "inventorySetQuantities",
"mutation_input": "{
"reason": "correction",
"ignoreCompareQuantity": true,
"quantities": [
{
"inventoryItemId": "gid://shopify/InventoryItem/46568206139693",
"locationId": "gid://shopify/Location/63312822306",
"name": "available",
"quantity": 12
}
]
}",
"api_version": "2026-01",
"hydration_type_patch": "{}"
}
Early Clues: GraphiQL Success and Community Pointers
Interestingly, ssg1205 had successfully tested the mutation directly in Shopify's GraphiQL app. Here's the mutation that worked there, changing an inventory value from 10 to 12:
mutation {
inventorySetQuantities(input: {
name: “available”,
reason: “correction”,
referenceDocumentUri: “logistics://replenishment/auto”,
quantities: [{
inventoryItemId: “gid://shopify/InventoryItem/47664006070573”,
locationId: “gid://shopify/Location/63312822306”,
quantity: 12,
changeFromQuantity: 10
}]
}) @idempotent(key: “replenish-47664006070573”) {
userErrors { field message }
}
}
This discrepancy between GraphiQL and Flow was a head-scratcher. The community quickly jumped in to help:
- tim_1 pointed out that
ignoreCompareQuantityis deprecated, andreferenceDocumentUri, while not always marked as required, was often necessary for these mutations to work correctly. Good stuff to keep in mind for API best practices!
The "Aha!" Moment: The Curly Quote Conundrum
The real breakthrough came from PaulNewton, who spotted a subtle but critical issue: curly quotes (“) instead of straight double quotes (") in the JSON strings. This might seem minor, but for machines parsing JSON, it's a huge deal!
Paul explained that this often happens when you copy-paste code from word-processing software, or sometimes even from AI tools or forum formatting that tries to be "smart" with typography. Here's how the problematic code looked in the forum, making those curly quotes visible:
{
“mutation_name”: “inventorySetQuantities”,
“mutation_input”: “{
“reason”: “correction”,
“referenceDocumentUri”: “logistics://replenishment/auto”,
“quantities”: [
{
“inventoryItemId”: “gid://shopify/InventoryItem/53885106422061”,
“locationId”: “gid://shopify/Location/63312822306”,
“name”: “available”,
“quantity”: 12
}
]
}”,
“api_version”: “2026-01”,
“hydration_type_patch”: “{}”
}
The crucial part here is the mutation_input string. When you embed a JSON string inside another JSON string (which is what Shopify Flow's 'Send Admin API request' action does), you need to be incredibly careful with escaping. Not only do the inner double quotes need to be escaped with a backslash (\"), but they also need to be straight double quotes. Curly quotes simply won't be recognized as valid JSON syntax by the API.
Your Blueprint for Successful Shopify Flow API Calls
So, what's the takeaway for anyone looking to automate with Shopify Flow and the Admin API? Here’s your action plan:
Step 1: Always use straight double quotes (")
This is paramount. If you're copying code, make sure your editor or IDE is set to use straight quotes, or manually replace any curly ones you find. This is especially true for the JSON string you pass into the mutation_input field.
Step 2: Ensure proper JSON escaping for nested strings
When your GraphQL mutation is provided as a string value for mutation_input, every double quote inside that string needs to be escaped with a backslash (\"). Newline characters should be
. This creates a valid string that the API can then parse back into a JSON object.
Step 3: Include required parameters like referenceDocumentUri
Even if the documentation doesn't explicitly mark a field as "required," sometimes the API expects it for certain operations. Including fields like reason and referenceDocumentUri for inventory mutations is a good practice.
Step 4: Test in GraphiQL first
As ssg1205 did, always test your GraphQL mutation directly in the Shopify GraphiQL Explorer app. This lets you confirm the mutation itself is valid before you introduce the complexities of Flow's API action.
Step 5: Use the code block formatter in forums (and your own tools!)
When seeking help or sharing code, using proper code formatting (like the triple backticks in forums) helps prevent character mangling and makes it easier for others to spot issues like curly quotes.
ssg1205's Creative Resolution: Beyond the API Call
In a fascinating twist, ssg1205 ultimately found a different path to their automated inventory goal. Instead of fixing the direct Flow API call, they utilized Shopify’s native AI to build a custom app that had a "replenish button." Then, they integrated this with Power Automate and Windows Task Scheduler to run a daily scheduled task that would effectively "click" that button.
This highlights an important lesson: sometimes, the most direct technical route isn't the only one. Exploring custom apps, AI-generated solutions, or even combining multiple tools can lead to the desired outcome, even if it's a bit unconventional. It's about finding what works for your specific setup and skill set.
So, whether you're battling curly quotes in your JSON or exploring AI-powered workarounds, remember that the Shopify community is a treasure trove of shared wisdom and diverse problem-solving approaches. Keep experimenting, keep learning, and don't be afraid to ask for help – you never know what crucial insight someone else might provide!