Method Signature
align.customers.list(email?: string): Promise<CustomerListResponse>
Parameters
Optional email address to filter results. Use for exact-match lookups.
Returns
Array of customer objects matching the query
Examples
List All Customers
import Align from "@tolbel/align";
const align = new Align({
apiKey: process.env.ALIGN_API_KEY!,
environment: "sandbox",
});
const response = await align.customers.list();
console.log(`Total customers: ${response.items.length}`);
// Iterate through customers
for (const customer of response.items) {
console.log(`${customer.email} - ${customer.type}`);
}
const response = await align.customers.list();
console.log("Total customers:", response.items.length);
response.items.forEach((customer) => {
console.log(`${customer.email} - ${customer.type}`);
});
Find Customer by Email
Use the email filter to find a specific customer:
const response = await align.customers.list("[email protected]");
if (response.items.length > 0) {
const customer = response.items[0];
console.log(`Found: ${customer.customer_id}`);
} else {
console.log("Customer not found");
}
Check if Customer Exists
Useful for preventing duplicate registrations:
async function customerExists(email: string): Promise<boolean> {
const response = await align.customers.list(email);
return response.items.length > 0;
}
// Usage
const email = "[email protected]";
if (await customerExists(email)) {
console.log("Customer already registered");
} else {
const customer = await align.customers.create({
email,
type: "individual",
first_name: "Alice",
last_name: "Smith",
});
}
Response Example
{
"items": [
{
"customer_id": "123e4567-e89b-12d3-a456-426614174000",
"email": "[email protected]",
"type": "individual",
"first_name": "Alice",
"last_name": "Smith",
"kycs": {
"status": "approved",
"sub_status": "kyc_form_submission_accepted"
}
},
{
"customer_id": "223e4567-e89b-12d3-a456-426614174001",
"email": "[email protected]",
"type": "individual",
"first_name": "Bob",
"last_name": "Johnson",
"kycs": null
}
]
}
The email filter performs an exact match. For partial matches, retrieve
all customers and filter client-side.