async function getAllContacts(credentialId, userId) {
let allContacts = [];
let offset = 0;
let hasMore = true;
while (hasMore) {
const response = await fetch(
'https://production.runalloy.com/connectors/hubspot/actions/listContacts/execute',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${YOUR_API_KEY}`,
'x-api-version': '{API_VERSION}',
'x-alloy-userid': userId,
'Content-Type': 'application/json'
},
body: JSON.stringify({
credentialId: credentialId,
actionId: 'listContacts',
input: {
limit: 50,
offset: offset
}
})
}
);
const result = await response.json();
allContacts = allContacts.concat(result.data);
hasMore = result.pagination.hasMore;
offset = result.pagination.nextOffset;
}
return allContacts;
}