Quickly Get Total Price Of Orders In Date Range

Shopify Partner
10 0 2

Hi, I'm looking to quickly (ideally in <10 seconds) get the sum of `total_price` of orders in the past 30 days for a store.

 

I could iterate through the orders using the "Orders" API, but that would take far longer than 10 seconds. Especially for larger stores.

 

Creating a Report with the ShopifyQL to calculate this seems promising, but it doesn't look like I'm able to get the content of the Report that I create.

 

Anyone know of a good way to get this from the Shopify API? Willing to entertain any ideas.

0 Likes
Shopify Staff
Shopify Staff
112 21 23

Hi @michaelm ,

 

If your store is on the Shopify Advanced plan or on Shopify Plus, you can leverage the Analytics API to directly send ShopifyQL queries and get the direct response. Here is a guide on how to set-up the Analytics API with some example requests and responses.

 

If your store is not on either of these plans, then I would say your best bet is to either use the Orders endpoint of the Admin API to retrieve all of your orders for the past 30 days and iterate through them all, or leverage the bulk operations with the GraphQL Admin API to save time fetching larger requests.

 

 

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

1 Like
Shopify Partner
10 0 2

Thanks for the quick reply and helpful links @hassain!

 

A few follow-up questions:

  • If I'm not running as an embedded app, is it possible for me to use the Analytics API? Is there a reason it's not available through the Admin API?
  • Is it possible to do aggregations using the Bulk API? (e.g. `sum(total_price)` )?
    • If not, do you think it'd still be faster to pull all orders in past 30 days through the Bulk API (if we're just interested in the "total_price" field)?
0 Likes
Highlighted
Shopify Staff
Shopify Staff
112 21 23

Glad you liked my post @michaelm ! To answer your follow ups:

 

If I'm not running as an embedded app, is it possible for me to use the Analytics API? Is there a reason it's not available through the Admin API?

You can only make requests to the Analytics API through an embedded app. The reason for this is because the Analytics API comes bundled with the Embedded App SDK 

 

Is it possible to do aggregations using the Bulk API? (e.g. `sum(total_price)` )?

From my knowledge, no this is not possible

 

If not, do you think it'd still be faster to pull all orders in past 30 days through the Bulk API (if we're just interested in the "total_price" field)?

This would depend on how many orders your store gets in the past 30 days. For larger stores with lots of orders, leveraging bulk operations with the GraphQL Admin API and only querying for the `total_price` field of orders would probably be the fastest option. However it may be worth running an A/B Test with these two methods to analytically determine the fastest approach for your store. 

 

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

0 Likes