Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!