stripe / stripe-node

Node.js library for the Stripe API.
https://stripe.com
MIT License
3.9k stars 755 forks source link

Prices.list throws error when ids array length rather than default limit (10) even when limit provided #2089

Closed bnikom closed 6 months ago

bnikom commented 6 months ago

Describe the bug

Whenever I call the stripe prices api

stripe.prices.list({ limit: pricesToFetch.length, lookup_keys: pricesToFetch });

i get an error

error: {
     "type": "Error",
     "stack":
        Error: Array lookup_keys exceeded maximum 10 allowed elements.
           at Function.generate (/packages/api/node_modules/stripe/cjs/Error.js:10:20)
           at res.toJSON.then.Error_js_1.StripeAPIError.message (/packages/api/node_modules/stripe/cjs/RequestSender.js:105:54)
           at processTicksAndRejections (node:internal/process/task_queues:95:5)
  }

To Reproduce

  1. Call stripe.prices.list with an id array longer than 10 (mine in 12) and a matching limit
  2. See error

Expected behavior

The api returns the same amount stripe prices requested from the limit param

Code snippets

export enum PLANS {
  // plans names have been changed
  a = 'a',
  b = 'b',
  c = 'c',
  d = 'd',
  e = 'e',
  f = 'f', 
  g = 'g',
  h = 'h',
  i = 'i',
  j = 'j',
  h = 'h',
  k = 'k',
}

export async function fetchStripePrices() {
   const plansToFetch = Object.values(PLANS) as string[];
   return stripe.prices.list({ limit: plansToFetch.length, lookup_keys: plansToFetch });
}

OS

macOS

Node version

Node v20.11.1

Library version

stripe-node v14.21.0

API version

2018-07-27

Additional context

No response

remi-stripe commented 6 months ago

@bnikom The List Prices API can not handle more than 10 separate values in the lookup_keys array so the error you are getting right now is expected and it's not something we plan to change in the future. The presence of limit is irrelevant in that case. I'll make sure our public docs are updated but you will have to ensure you don't pass more than 10 values in that array. Since this is more an integration support question, please work with our support team at https://support.stripe.com/contact if you have follow up questions.