Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,23 @@ export const options = {
'Content-Type': 'application/json'
}
}

// Airtable API is limited to 100 items per page
export async function fetchAllPages(fetch: any, url: any) {
let allRecords: any[] = []
// https://airtable.com/developers/web/api/list-records#query-pagesize
let offset

do {
const fullUrl = offset ? `${url}?offset=${offset}` : url
const response = await fetch(fullUrl, options)
if (!response.ok) {
throw new Error('Failed to fetch data from Airtable')
}
const data: any = await response.json()
allRecords = allRecords.concat(data.records)
offset = data.offset
} while (offset)

return allRecords
}
Loading