Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda