Efficient way to get a list of store credit accounts with balance

Hi, is there an efficient way to get a list of store credit accounts with balance w/o looping through all customers one by one?

The only way that I am aware of is to loop through all customers w/o a way to narrow it down to customers with store credit account, which is very inefficient: customers - GraphQL Admin

Hey Andrew,

I asked the .dev assistant on shopify.dev and it suggested that it should be possible to “efficiently retrieve a list of store credit accounts with balances without looping through all customers, you can use the storeCreditAccounts field available on the Customer object. This field allows you to query store credit accounts directly, and you can use filters like query to narrow down the results to accounts with balances.”

Here’s an example query:

query GetStoreCreditAccountsWithBalance {
  customers(first: 10) {
    edges {
      node {
        id
        displayName
        storeCreditAccounts(query: "balance.amount:>0") {
          edges {
            node {
              id
              balance {
                amount
                currencyCode
              }
            }
          }
        }
      }
    }
  }
}

Can you test that out? I don’t have customers with store credit to test it on myself.

This will still need to loop through all customers with customers(first: 10) and pagination. It would work if shopify supports this instead: customers(first: 10,query: “balance.amount:>0”)

Hi again Andrew,

I’ve connected with the store credit team to see if there’s a more efficient method, or if they are considering investing in building support for other methods.

Hi Andrew,
Eileen here from the store credit team. There isn’t a better way to do this at the moment. We have an item in our backlog to create a top level query that will allow you to do this type of filtering much more efficiently. I don’t have a specific timeline for this to share, but we will post in the changelog when available.
Also worth noting, in admin you can now build customer segments based on store credit balance.

1 Like