JavaScript - Updating API URL with Offset on Button Click?

hey man, i had the same issue. try this:

let offset = ‘’;
const baseUrl = ‘https://api.airtable.com/v0/myBaseId/myTable?apiKey=myKey’;

async function getData() {
const url = ${baseUrl}&offset=${offset};
const res = await fetch(url);
const data = await res.json();
offset = data.offset || ‘’;
// do stuff with data
}

document.getElementById(‘nextPage’).onclick = getData;

this way you update offset each time u fetch. hope it helps!