//native
/**
* Search Customers
* Search customers with Shopify's search syntax (e.g. `email:jane@example.com`, `country:France`, `tag:vip orders_count:>3`, or free text matching name, email and phone). Leave query empty to list them all. Returns one page; pass pageInfo.endCursor as after to get the next one.
*/
export async function main(
auth: RT.Shopify,
query: string | undefined,
sort_key:
| "UPDATED_AT"
| "CREATED_AT"
| "NAME"
| "LOCATION"
| "ID"
| "RELEVANCE"
| undefined,
reverse: boolean | undefined,
first: number | undefined,
after: string | undefined
) {
const response = await fetch(
`https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
{
method: "POST",
headers: {
"X-Shopify-Access-Token": auth.token,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `query ($first: Int!, $after: String, $query: String, $sortKey: CustomerSortKeys, $reverse: Boolean) { customers(first: $first, after: $after, query: $query, sortKey: $sortKey, reverse: $reverse) { nodes { id legacyResourceId displayName firstName lastName state tags note locale verifiedEmail taxExempt numberOfOrders amountSpent { amount currencyCode } createdAt updatedAt defaultEmailAddress { emailAddress marketingState marketingOptInLevel } defaultPhoneNumber { phoneNumber } defaultAddress { name firstName lastName company address1 address2 city provinceCode zip countryCodeV2 phone } } pageInfo { hasNextPage endCursor } } }`,
variables: {
first: first || 50,
after: after || undefined,
query: query || undefined,
sortKey: sort_key || undefined,
reverse: reverse || undefined,
},
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data, errors } = await response.json()
if (errors) {
throw new Error(JSON.stringify(errors))
}
return data.customers
}
Submitted by hugo989 3 hours ago