A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello, Shopify team, we are following the latest API Docs here: https://shopify.dev/docs/api/admin-graphql/2024-04/queries/inventoryLevel#returns
Looks like we need to pass all the `STATE` filters at once to fetch them all, as we need.
1) Is there a way not to pass them explicitly but have the `wildcard` selection instead: `*,` `ALL`?
2) Alternatively, could this be modified the way the `names` is not a mandatory filter, meaning, if not specified - all of the STATES should be returned?
Thanks!
Hi @Airbyte,
At this time there is no way to specify all inventory states in the InventoryLevels.quantities query, without passing them all in as arguments. I do see how this could benefit your business operations and I will be passing feedback on to our developers that you would like to see this added as a feature in the future! We do take all our merchants and partners feedback into great value when determining future changes and updates on the platform.
That said you are also able to pass variables into GraphQL query inputs, so if you are needing to make multiple InventoryLevels.quantities queries for all inventory states, then in your app code you can define an array that contains all the states and just pass that single array into the query input each time, here's an example of the graphQL query with the variables:
In your app code, define an array of strings with the state names:
STATEARRAY = [
"available",
"incoming",
"committed",
"damaged",
"on_hand",
"quality_control",
"reserved",
"safety_stock"
]
GraphQL Query Body:
query inventoryLevel($inventoryId: ID!, $stateNames: [String!]!) {
inventoryLevel(id: $inventoryId) {
id
quantities(names: $stateNames) {
name
quantity
}
item {
id
sku
}
location {
id
name
}
}
}
GraphQL Query Variables:
{
"inventoryId": "gid://shopify/InventoryLevel/103507165346?inventory_item_id=46195070501026",
"stateNames": #{STATEARRAY}
}
NOTE: this example is using Ruby syntax to define the array and pass it into the graphQL variable input string. The syntax or method to do this may differ depending on what programming language and frameworks you are using.
I hope this helps, and I hope you have a great day 🙂
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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