Search code examples
javascriptnode.jsapiemailstripe-payments

How to retrieve customers by email in node.js (Stripe)


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.


Solution

  • 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.