I’m trying to get a total number of customers in the store or all the customer list id’s in the store using GraphQl admin API, Can anyone give solution for this?
Topic summary
Goal: obtain the total number of customers or all customer IDs via Shopify’s GraphQL Admin API.
- One response states GraphQL does not provide a customer count endpoint and advises using the Admin REST API “Get customers count” endpoint (link provided).
- Another provides a GraphQL query to list all customer IDs using the customers connection with pagination (first: 250, edges { node { id } }, pageInfo with hasNextPage/endCursor), implying you must paginate to retrieve all IDs.
- The original poster later shares a working GraphQL example to get the total count directly: a customersCount query returning count, implemented via a POST to /admin/api/graphql.json, and reports it succeeded for them.
Outcome: Two viable approaches are presented—REST API for direct count and GraphQL customersCount for count (as reported by OP), plus a GraphQL pattern for paginated retrieval of all IDs. There is a minor disagreement on GraphQL support for counts; no further confirmation from others. Code snippets are central to understanding the solutions. Discussion appears effectively resolved by the OP’s GraphQL example.
graphql does not have such an api, use the rest api.
https://shopify.dev/docs/api/admin-rest/2024-10/resources/customer#get-customers-count
Hi,there
all the customer list ids. pls refer to below code
query GetAllCustomerIDs {
customers(first: 250) {
edges {
node {
id
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
hi @Eric-HAN
const res = await fetch(‘shopify:admin/api/graphql.json’, {
method: ‘POST’,
body: JSON.stringify({
query: query { customersCount{ count } }
}),
});
const data= await res.json();
const customerCount= data.data.customersCount.count;
I have got total number of customers using this query , IT might help someone. thank you.
Hi @Kyle_liu
Thankyou, Please refer my solution.