Reputation: 207
I have this:
const customer = await stripe.customers.retrieve(
'[email protected]'
);
I'm trying to get the customer number (id) of the customer based on the email address. Is this possible through stripe? It gives me an error when I do this.
Upvotes: 3
Views: 3589
Reputation: 1
Using "list()" and "search()", you can get customers by email with these Node.js code below:
const customers = await stripe.customers.list({
email:"[email protected]",
});
const customers = await stripe.customers.search({
query:"email:'[email protected]'",
});
You can also limit customers to get with "limit" parameter as shown below:
const customers = await stripe.customers.list({
email:"[email protected]",
limit: 3,
});
const customers = await stripe.customers.search({
query:"email:'[email protected]'",
limit: 3,
});
Upvotes: 2
Reputation: 2784
You will need to use https://stripe.com/docs/api/customers/list and it will return a list of customers with that particular email address.
const customers = await stripe.customers.list({
email: '[email protected]',
});
Note that there is a limit on the number of objects to be returned. You should make use of auto pagination in case there is a large number of customers with the same email.
Upvotes: 8