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

90
Vistas
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 Respuestas
Responde la pregunta

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 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