Discussing APIs and development related to customers, discounts, and order management.
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!
Solved! Go to the solution
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
}
}
}
}
}
}
}
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
}
}
}
}
}
}
}
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.