I'm trying to return all products and plans list from stripe.
However the products list return empty even though there's a active
product created.
function getProductsAndPlans() {
return Promise.all([
stripe.products.list({}),
stripe.plans.list({}),
]).then(stripeData => {
console.log('products', stripeData[0]) <-- this is empty
console.log('plans', stripeData[1]) <-- this returns plans
}).catch(err => {
console.error('Error fetching Stripe products and plans: ', err);
return [];
});
}
Here are the products from my stripe dashboard:
Plans get returned:
But the products list is empty:
Here's a copy from the stripe doc.
const stripe = require('stripe')('sk_test_smkOYa912GSsdfdfDDfByiohm');
const products = await stripe.products.list({
limit: 3,
});
What am I missing here?
I'm trying to return all products and plans list from stripe.
However the products list return empty even though there's a active
product created.
function getProductsAndPlans() {
return Promise.all([
stripe.products.list({}),
stripe.plans.list({}),
]).then(stripeData => {
console.log('products', stripeData[0]) <-- this is empty
console.log('plans', stripeData[1]) <-- this returns plans
}).catch(err => {
console.error('Error fetching Stripe products and plans: ', err);
return [];
});
}
Here are the products from my stripe dashboard:
Plans get returned:
But the products list is empty:
Here's a copy from the stripe doc.
const stripe = require('stripe')('sk_test_smkOYa912GSsdfdfDDfByiohm');
const products = await stripe.products.list({
limit: 3,
});
What am I missing here?
Share Improve this question asked Nov 9, 2020 at 12:58 AzimaAzima 4,15115 gold badges58 silver badges113 bronze badges1 Answer
Reset to default 10Most likely this is related to the API changes from 2018-02-05, when the default behaviour switched from type=good
to type=service
, and your account probably having a default API version predating that. Your Product is likely a type=service
which, as documented, are omitted for Product list requests from older API version by default.
To get the products list request to include the products you're using in the dashboard, you can do one of the following:
- Explicitly request
service
Products withstripe.products.list({type: 'service'})
(as noted in the API changelog) - Override your default API for that request, with
stripe.products.list({}, {apiVersion: '2018-02-05'})
(or any later version) - Upgrade your account default API version