Graphql access to InventoryItem

Hi, I need to get access to the inventoryHistoryUrl in the object InventoryItem via GraphQL

I need to get programmatic access to the history so we can basically screen scrape the history and put it in table format.

The Graphql documentation seems wrong, the following request does not work:

curl -X POST \
https://your-development-store.myshopify.com/admin/api/2023-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "query { inventoryItem(id: "gid://shopify/InventoryItem/30322695") { id tracked sku } }"
}'

[Direct from the docs from Shopify]

Obviously I put in my access_token, my actual store URL, and the inventory item from the .json structure of the product and variant:

Has anyone got this working (getting the inventory item back via GraphQL) ?? I know I can add the inventoryHistoryUrl field in the request once it works.

Or is their a better way to get the inventory history for a variant which is all I care about.

Thanks.

Hey @fwallace

Here’s a very simple query where you can get a list of inventory items and the corresponding history URL.

{> inventoryItems(first: 10) {> nodes {> inventoryHistoryUrl> }> }> }

Adding a query filter can also help narrow this down to a specific product/variant, for example with a sku

{> inventoryItems(first: 10, query: "sku:

Or if you have the variant ID, you can use a query like this to get the inventoryItem id and URL

{> productVariant(id: “gid://shopify/ProductVariant/12345678910”) {> id> inventoryItem {> id> inventoryHistoryUrl> }> }> }

Hopefully that gives you an idea of a few ways that this can be achieved!

  • Kyle G.