I’m working on integrating with HubSpot’s API and I’m struggling with implementing proper pagination for retrieving contact records. I’m using the official HubSpot Node.js client library.
hubspotAPI.crm.contacts.basicApi
.getPage(pageLimit, afterToken, fields, fieldsWithHistory, relationships, includeDeleted)
.then((response) => {
console.log(response)
})
.catch((error) => {
console.error(error)
})
I understand that the afterToken parameter accepts a contact ID and returns records starting from that specific ID onwards. However, I’m not sure how to properly implement pagination logic using this approach. Should I be storing the last contact ID from each response and using it as the afterToken for the next request? Is there a better way to handle pagination with HubSpot’s API, or am I on the right track with this method?