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

96
Visualizações
Javascript API fetch loop using offset

I'm fetching data from an API that has a limit of 50 records per call. There are 10,000 records in total that I need to retrieve so looking at using pagination via the offset parameter to achieve this.

I'm not too familiar with the syntax I need to use but I would like to keep looping through the fetch until the number of records returned for a single call is < 50 to signal the final page.

I need my JSON responses from each call to be appended together, in addition to a final 'count' that gives me 10,000

let offset = 0

       fetch(`https://api.opensea.io/api/v1/assets?collection=womenandweapons&format=json&offset=${offset}&limit=50&order_direction=desc`, 
      {
      method: 'GET',
      headers: {
        'Accept': 'application/json'
      }
        
      })
    
    .then(response => response.json())
    .then(data => {

      let len = Object.keys(data.assets).length
      console.log(len)
      console.log(data.assets)
    })
    
    
    offset += 50
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I've had some luck doing something like this:

const main = async () => {
    const url = new URL(AIRTABLE_URL);
    let data = await fetcher(url, AIRTABLE_API_KEY);
    storiesTotal = mapData(data.records);

    while (data.offset) {
      data = await fetcher(url, AIRTABLE_API_KEY, data.offset);
      storiesTotal = [...storiesTotal, ...mapData(data.records)];
    }
  }

main();
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