async function fetchAllRecords(accountId) {
const records = [];
let cursor = null;
do {
const url = new URL('https://api.usehandled.io/api/v1/ipaas/unified/crm/contacts');
url.searchParams.set('integrated_account_id', accountId);
if (cursor) url.searchParams.set('next_cursor', cursor);
const response = await fetch(url, {
headers: { 'Authorization': `Bearer ${API_TOKEN}` }
});
const data = await response.json();
records.push(...data.result);
cursor = data.next_cursor;
} while (cursor);
return records;
}