Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Get Total Spent Over Time by Customer ID Via GraphQL

Solved

Get Total Spent Over Time by Customer ID Via GraphQL

mv5
Shopify Partner
31 2 4

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
275 30 29

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
275 30 29

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
Shopify Partner
31 2 4

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.