Getting Current Inventory Levels of Products based on Order Line Items

Solved
Highlighted
New Member
3 0 0

Hello,

I am trying to build a dashboard using the GraphQL API.

I have put together a query that gives me order id and name from a certain date range which then provides me lineItems, fulfillmentStatus, title, quantity on the order, sku, variantTitle, and any customAttributes found on the orders within the date range:

 

mutation {
  bulkOperationRunQuery(
   query:"""{
  orders(query:"created_at:>2020-05-01-01T04:00:00Z created_at:<2020-07-30-01T04:23:59Z") {
    edges {
      node {
        id
        name
        createdAt
        lineItems(first: 15) {
          edges {
            node {
              fulfillmentStatus
              title
              quantity
              sku
              variantTitle
              customAttributes {
              value
              }
            }
          }
        }
      }
    }
  }
}
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

 

I poll the URL and get my JSONL file and then parse it within my BI program and I then massage the data.

 

The question I have regarding the query above is: Would it be possible to get the current on hand inventory as well so it appears next to each product listing? 

I searched the documentation and it doesn't appear that there is a straightforward way to query the current inventory quantities based on products from the orders. 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
582 70 127

This is an accepted solution.

Hey @ner,

This should work if you query the variant connection on lineItems

{
  orders(query:"created_at:>2020-05-01-01T04:00:00Z created_at:<2020-07-30-01T04:23:59Z") {
    edges {
      node {
        id
        name
        createdAt
        lineItems(first: 15) {
          edges {
            node {
              fulfillmentStatus
              title
              quantity
              sku
              variantTitle
              customAttributes {
              value
              }
              ---------
              variant {  
                  inventoryQuantity
              }
              ---------
            }
          }
        }
      }
    }
  }
}

 

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
New Member
3 0 0

That works when I port it over to my bulk query (with addition of a curly bracket to complete the statement for bulk queries).

Now I have to parse the inventoryQuantity field to make it discreet attribute of each line/SKU

Thanks!

0 Likes