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.

GraphQL `InventoryLevels.quantities` issue with `names` state filter (2024-04)

GraphQL `InventoryLevels.quantities` issue with `names` state filter (2024-04)

Airbyte
Shopify Partner
7 0 2

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!

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1453 238 525

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