forked from NangoHQ/nango
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pagination errors in hubspot sync templates
- Loading branch information
1 parent
dfe07c6
commit ade4c5e
Showing
9 changed files
with
239 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { HubspotOwner, NangoSync } from './models'; | ||
|
||
export default async function fetchData(nango: NangoSync) { | ||
let totalRecords = 0; | ||
|
||
try { | ||
const endpoint = '/crm/v3/owners'; | ||
const config = { | ||
paginate: { | ||
type: 'cursor', | ||
cursor_path_in_response: 'paging.next.after', | ||
limit_name_in_request: 'limit', | ||
cursor_name_in_request: 'after', | ||
response_path: 'results', | ||
limit: 100 | ||
} | ||
}; | ||
for await (const owner of nango.paginate({ ...config, endpoint })) { | ||
const mappedOwner: HubspotOwner[] = owner.map(mapOwner) || []; | ||
|
||
const batchSize: number = mappedOwner.length; | ||
totalRecords += batchSize; | ||
await nango.log(`Saving batch of ${batchSize} owners (total owners: ${totalRecords})`); | ||
await nango.batchSave(mappedOwner, 'HubspotOwner'); | ||
} | ||
} catch (error: any) { | ||
throw new Error(`Error in fetchData: ${error.message}`); | ||
} | ||
} | ||
|
||
function mapOwner(owner: any): HubspotOwner { | ||
return { | ||
id: owner.id, | ||
email: owner.email, | ||
firstName: owner.firstName, | ||
lastName: owner.lastName, | ||
userId: owner.userId, | ||
createdAt: owner.createdAt, | ||
updatedAt: owner.updatedAt, | ||
archived: owner.archived | ||
}; | ||
} |
Oops, something went wrong.