简体   繁体   中英

retrieve customer by email address stripe node.js

I have this:

const customer = await stripe.customers.retrieve(
  'info@myemail.com'
);

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.

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: 'info@myemail.com',
});

Note that there is alimit 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.

Using "list()" and "search()" , you can get customers by email with these Node.js code below:

const customers = await stripe.customers.list({
  email:"info@myemail.com",
});
const customers = await stripe.customers.search({
  query:"email:'info@myemail.com'",
});

You can also limit customers to get with "limit" parameter as shown below:

const customers = await stripe.customers.list({
  email:"info@myemail.com",
  limit: 3,
});
const customers = await stripe.customers.search({
  query:"email:'info@myemail.com'",
  limit: 3,
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM