Skip to content

Instantly share code, notes, and snippets.

@Dzhuneyt
Last active June 1, 2022 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dzhuneyt/b183a488874bfa7055b9167f9a889578 to your computer and use it in GitHub Desktop.
Save Dzhuneyt/b183a488874bfa7055b9167f9a889578 to your computer and use it in GitHub Desktop.
Delete all Customers in a Stripe account - through the Stripe SDK for JS
import {Stripe} from 'stripe';
const STRIPE_API_KEY = process.env.STRIPE_API_KEY;
const s = new Stripe(STRIPE_API_KEY, {
apiVersion: "2020-08-27",
});
const deletePage = async () => {
const customers = await s.customers.list();
for (let customer of customers.data) {
const before = new Date().getTime();
await s.customers.del(customer.id);
const after = new Date().getTime();
console.log('Deleted', customer.id, 'in', after - before, 'ms');
}
if (customers.has_more) {
console.log('Going to next page...');
await deletePage();
}
}
deletePage().then();
@Dzhuneyt
Copy link
Author

Dzhuneyt commented Jun 1, 2022

Usage:

export STRIPE_API_KEY="sk_xxxxxx...."
node ./delete-all-stripe-customers.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment