You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Stripe API获取产品列表为空,已有活跃产品但Plans可正常返回

Troubleshooting Empty Products List in Stripe API (While Plans Return Successfully)

Let’s break down the most likely reasons your stripe.products.list() call is returning an empty result, even though you can see active products in your Stripe Dashboard.

1. You’re not accessing the data property of the API response

Stripe’s list endpoints wrap results in an object, and the actual array of products lives in the nested data field. Looking at your code:

console.log('products', stripeData[0])

If you’re checking this log and seeing an object that doesn’t show product items at first glance, you’re probably missing the .data property. Update your log statement to:

console.log('products', stripeData[0].data)

This is the most common mistake with Stripe’s list calls—always make sure you’re targeting the nested data array, not the top-level response object.

2. API Version Mismatch

Stripe’s API evolves over time, and older versions might not retrieve products created with newer API versions, or might require different parameters.

  • Check the default API version in your Stripe Dashboard (under Developers > API Keys).
  • Ensure your code uses the same version. If you’re initializing Stripe without specifying a version, it uses the Dashboard’s default. To explicitly set it:
    const stripe = require('stripe')('sk_test_smkOYa912GSsdfdfDDfByiohm', {
      apiVersion: '2024-06-20', // Match the version from your Dashboard
    });
    

3. Explicit Filter Parameters Might Be Needed

While stripe.products.list({}) should return all active products by default, adding explicit filters can resolve unexpected empty results:

  • Try explicitly requesting active products to match what you see in the Dashboard:
    stripe.products.list({ active: true })
    
  • If you suspect archived products are causing confusion, you can include them with active: null, but this is unlikely if you’ve confirmed your products are active.

4. Verify Your API Key and Account Context

  • Double-check that the sk_test_ secret key in your code belongs to the same Stripe account where you created the products—it’s easy to mix up test/live keys or different accounts by accident.
  • Ensure your key has the read_products permission. Full-access test keys (the default sk_test keys) include this, but restricted keys need explicit access to product data.

5. Check Product Type Compatibility

If your products are tied to specific types (like subscriptions), older API versions might require additional parameters to retrieve them. However, since your plans are returning correctly, this is less likely to be the issue.


内容的提问来源于stack exchange,提问作者Azima

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 20:02:57