A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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!
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!
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.