Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
Get more than 100 charge data from Stripe API in Node JS

I am trying to get all the charge data from stripe api. By default, stripe doesn't allow fetching more than 100 data and I have thousands of data there. There's a field in stripe called has_more, which provides info about if there's more data through it's true/false value. Now. I'm trying to automate the process in node js so that, first of all, an API call to fetch 100 data, then it'll check if has_more is true. If true, then it'll take the id of the last object in data and start fetching data after that id and keep doing it untill has_more returns false.

I've done this till now, which gets only the first 100 data. Can anyone give any idea on the next process?

async function getData() {
  const data = await axios.get(
    `${URL}?created%5Bgte%5D=${created}&created%5Blte%5D=${createdEnd}&limit=${limit}`,
    {
      headers: {
        Authorization: `Bearer ${bearer}`,

        "Stripe-Account": `${stripe_account}`,
      },
    }
  );

  return data;

}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I'd do:

async function getData(startingAfter) {
  let url = `${URL}?created%5Bgte%5D=${created}&created%5Blte%5D=${createdEnd}&limit=${limit}`
  // if they pass in a startingAfter param, use it
  if (typeof startingAfter !== 'undefined') {
      url += `&starting_after=${startingAfter}`
  }
  const data = await axios.get(url
   ,
    {
      headers: {
        Authorization: `Bearer ${bearer}`,
        "Stripe-Account": `${stripe_account}`,
      },
    }
  );
  // if there is more, add the additional items to this list, and
  // then set hasMore to false (since we fetched them all)
  if (data.hasMore) {
      const more = await getData(data[data.length - 1].id);
      data.data.push(...more.data)
      data.hasMore = false;
  }
  return data;

}

This will get the first 100 items, see it has more, and then call getData(100) (well, getData('ch_whatever_the_id_is_for_#_100')), which will fetch the next 100 items, then call getData(200), etc. etc. etc., and then your initial call will end up with the full list.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You should install the official stripe-node library and use the library's in-built auto-pagination.

https://stripe.com/docs/api/pagination/auto?lang=node

Also are you using axios on the frontend? You can't do that since that would mean you're exposting your secret Stripe API key on the frontend, listing charges is a backend API call (so you should be able to install and use stripe-node https://github.com/stripe/stripe-node)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda