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.

Getting Current Inventory Levels of Products based on Order Line Items

Solved

Getting Current Inventory Levels of Products based on Order Line Items

ner
Shopify Partner
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. 

banned
Accepted Solution (1)

_JB
Shopify Staff (Retired)
836 100 223

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 | Solutions Engineer @ Shopify 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

_JB
Shopify Staff (Retired)
836 100 223

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 | Solutions Engineer @ Shopify 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ner
Shopify Partner
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!

banned