Query order statistics/metrics via GraphQL

Query order statistics/metrics via GraphQL

ells-t
Tourist
4 0 1

I understand that I can do a bulk query to get a list of all orders for a specific time range and just do the count programmatically based on the resulting `jsonl` file. But is it possible to query GraphQL to basically get a count of orders group by financial status and fulfillment status base on timerange? 

 

I also do see we can do ShopifyQL queries as query to GraphQL request but lets say we don't have access to do that, is there another way to easily get these statistics? 

Thank you!

 

 

Reply 1 (1)

Liam
Shopify Staff
2873 312 821

Hi Ells-T,

 

Yes, you can query GraphQL to get a count of orders grouped by financial status and fulfillment status based on a time range. You would do this by creating a custom connection where the edges are the orders, and the nodes contain the financial status and fulfillment status. However, note that you would still need to count the order statuses programmatically from the returned data.

Here's an example query:

{
  orders (first: , query: "created_at:2023-08-0100:00:00Z TO 2023-10-01T23:59:59Z") {
    edges {
      node {
        id
        financialStatus
        fulfillmentStatus
      }
    }
  }
}

The query parameter in the orders field filters based on a time range (in this case, orders created between August 1, 2023 and October 1, 2023).

 

Unfortunately, GraphQL does not have built-in support for aggregation operations like count, sum, group by, etc. So, you would need to do this programmatically.

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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