Get Total Spent Over Time by Customer ID Via GraphQL

Solved

Get Total Spent Over Time by Customer ID Via GraphQL

mv5
Excursionist
28 2 2

Is it possible to query total amount spent by a customer (minus discounts) over a duration of time (since: 01-01-2024 for example) via GraphQL? Wanting to update a customer record sheet automagically with Python. I can't find anything similar in the GraphQL docs.

 

I guess theoretically I could pull all orders per customer (is there a bulkOperation for this so I don't run out of tokens?) and only pull data from ones matching dates but that seems slower than just pulling a total amount from Shopify which is already stored in the system so I figured there's a query I'm missing somewhere.

 

Thanks a ton!

Accepted Solution (1)

Eric-HAN
Shopify Partner
99 15 8

This is an accepted solution.

HI, there

 

I think there is no built-in  field or query specifically dedicated to retrieving the total amount spent by a customer.

But you can achieve this by querying one customer orders and calculate the total spent by yourself. 

Here is the GraphQl you could refer.

 

query {
  customer(id: "gid://shopify/Customer/7178588193051") {
    orders(first: 10, query: "created_at:>2024-01-01") {
      edges {
        node {
          totalPriceSet {
            presentmentMoney {
              amount
            }
          }
        }
      }
    }
  }
}

 

 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee

View solution in original post

Replies 2 (2)

Eric-HAN
Shopify Partner
99 15 8

This is an accepted solution.

HI, there

 

I think there is no built-in  field or query specifically dedicated to retrieving the total amount spent by a customer.

But you can achieve this by querying one customer orders and calculate the total spent by yourself. 

Here is the GraphQl you could refer.

 

query {
  customer(id: "gid://shopify/Customer/7178588193051") {
    orders(first: 10, query: "created_at:>2024-01-01") {
      edges {
        node {
          totalPriceSet {
            presentmentMoney {
              amount
            }
          }
        }
      }
    }
  }
}

 

 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
mv5
Excursionist
28 2 2

Thanks! This was exactly the query I needed. Just looped thru querying by each ID I was interested in per customer. Then summed all the order amounts.