Limit total spent by a customer in a particular duration using Cart and Checkout validation API

How to get total amount spent by a customer in a particular duration (day, week, month, custom) in Shopify using API?

Specifically, I need to limit customers spent on the store in those duration using Cart and Checkout validation API. Like a customer can only purchase products worth $1000 in a month

How would you implement that?

Hi Jacob,

You can use the customer query to fetch a customer’s orders, and filter orders by date using the query parameter. Then you’d sum up the totalPriceSet field from the retrieved orders to calculate the total amount spent, and create logic from there.

Hey Liam, I believe the OP is doing this inside a Shopify Function, specifically the Validation API. Although this is available in the Validation API it is only for the Enterprise plan.

I wish there was a native query just to calculate the total instead of looping through all the orders and then sum up the total.

For now, I have decided to go with:

  • A proxy URL in the app which receives the customer ID
  • FLOW calls the proxy URL whenever there is a new order with the customer ID in the URL.
  • The app/proxy find all the orders for that customer in the period and updates in a metafield.

Why not webhook: Webhooks has a short timeout and I don’t want to deal with queueing the requests.