Accessing "Last order Date", "Total orders" and "Amount spent" fields for each customer

Accessing "Last order Date", "Total orders" and "Amount spent" fields for each customer

Malthe
Tourist
7 0 3

Hi!

In the Shopify admin under "Customers" a merchant can sort customers by different parameters. I'm specifically thinking about the "Last order Date", "Total orders" and "Amount spent".

I was wondering how this information could be accessed through the Shopify api's. I'm strictly interested in the information for each customer, thus I don't need to sort the results from a search query. I know that the  rest and graphql api's provide the "Amount Spend" field for each customer, but the two other fields seem to be absent.

How would you go about getting this information? Currently I can only think of a solution were my app would query the customers/{customer_id}/orders.json endpoint for each and every customer, but that seems a little overkill since the information is already computed internally in the Shopify admin.

Thanks in advance!

Replies 4 (4)

Gregarican
Shopify Partner
1033 86 292

The Customer REST API endpoint exposes all these properties --> https://shopify.dev/docs/admin-api/rest/reference/customers/customer. Specifically order_count, total_spent, and last_order_id (or last_order_name if that's what you prefer).

Hope this helps! 

Malthe
Tourist
7 0 3
Thanks for your reply! I wasn't even aware of that, must have missed it
then.

Do you know if the 'last_order_id' in itself exposes any information about
the date of the associated order?
Or is the only way to get that by requesting the order api?
Gregarican
Shopify Partner
1033 86 292

If we are talking about the REST API, then you would need to query the Order endpoint for that information. If you chose to use the GraphQL API instead then you could expand the Order in the original Customer API response and see whatever order fields you want --> https://shopify.dev/docs/admin-api/graphql/reference/customers/customer#fields-2021-01

Malthe
Tourist
7 0 3
Awesome. Thanks so much for the information!