Can I use GQL to return the number of customers, orders, line items, etc

For an external application, I need to daily get the number of customers, orders and inventory items. I am using GQL in a node rest implementation and would like to continue using GQL. Is this possible?

Thanks
Bruce

Hey Bruce,

You should be able to use these GQL queries to achieve this:

Are these not working for your use-case?

Sorry, I was not smart enough to see the options on the left for the customers and orders. However, I do not see any option for count of inventory items.

Thanks
Bruce

From looking into this more, it seems you’d need to use the inventoryLevel query instead which has a quantities field, but you’d need to have the inventory_item_id first.

Thanks for the reply, but I am not looking to see the quantity but I want the number of inventory SKUs. So this will not help. But thanks

Each inventory item has 1-1 relation with variants. So you can use productVariantsCount to count inventory_item count as well. Better to test first.

@Bruce_Lomasky one thing to keep in mind if you’re using these count queries is that the number of results are often capped at 10,000.

Not sure of the number of records you’re dealing with but it can be unexpected if you’re not aware of it

Thanks! You da MAN! I never would have thought of this.

Happy new year!
(And stay warm!)

Bruce

productVariantsCount is not capped at the moment but the order is.

Thanks for all of the help so far. So since the customers and orders are capped at 10K, I figured I could filter them for just customers created this year. Unfortunately the following does not work:

query CustomerCount {
customersCount (created_at:<=2025) {
count
}
}

I get an error at the < sign.

Bruce

And, of course, after sending this email, I figured it out. Always happens!!!

Bruce