javascriptstripe-payments

Can I get a list of Stripe subscriptions with multiple statuses?


I'm using:

    const stripeCustomerSubscriptions = await stripe.subscriptions.list({
        customer: req.body.stripeCustomerId,
        status: 'active'
    });

and that gets me all active subscriptions. But I want all active and trialing. Any way to specify both?


Solution

  • Per Stripe API docs if we want to retrieve more than one status we should specify "all" in the status field and filter the results that we get back by ourselves.

    The code should look something like:

    const stripeCustomerSubscriptions = await stripe.subscriptions.list({
            customer: req.body.stripeCustomerId,
            status: 'all'
        });
    
    const filteredSubs = stripeCustomerSubscriptions.data.filter(sub => sub.status === 'active' || sub.status === 'trialing');