Fetch customers
We provide a number of methods for fetching customers:
- Get customers (To fetch more than one customer at a time)
- Get customer by ID
- Get customer by email
All of these endpoints require the following permissions:
customer:read
Get customers
Our API allows you to fetch customers as a collection using getCustomers
in our SDKs or the customers
query in GraphQL. In both cases this endpoint supports Pagination.
This is a very flexible endpoint which supports a variety of options for filtering and sorting, for full details try our API explorer or Typescript SDK.
import { PlainClient } from '@team-plain/typescript-sdk';
const client = new PlainClient({ apiKey: 'plainApiKey_xxx' });
const res = await client.getCustomers({
first: 50,
filters: { isMarkedAsSpam: false },
sortBy: { field: CustomersSortField.FullName, direction: SortDirection.Asc },
});
if (res.error) {
console.error(res.error);
} else {
console.log(res.data);
}
Get customer by ID
If you already have the ID of a customer from within Plain or one of our other endpoints you can fetch more details about them using getCustomerById
in our SDKs or the customer
query in GraphQL.
import { PlainClient } from '@team-plain/typescript-sdk';
const client = new PlainClient({ apiKey: 'plainApiKey_xxx' });
const res = await client.getCustomerById({
customerId: 'c_01H14DFQ4PDYBH398J1E99TWSS',
});
if (res.error) {
console.error(res.error);
} else {
console.log(res.data);
}
Get customer by email
To fetch a customer by email you can use getCustomerByEmail
in our SDKs or the customerByEmail
query in GraphQL.
import { PlainClient } from '@team-plain/typescript-sdk';
const client = new PlainClient({ apiKey: 'plainApiKey_xxx' });
const res = await client.getCustomerByEmail({ email: 'bob@example.com' });
if (res.error) {
console.error(res.error);
} else {
console.log(res.data);
}
Was this page helpful?