improvements in fetchLeadsFromKeystone.js
This commit is contained in:
1 parent
1b7cd4899e
commit
7a7dcfe3ad
2 files changed
+10
-5
No files matched your search
@@ -18,12 +18,17 @@ async function getLeads(lastRunDate, currentDate, unsent, test) {
|
|||||||
unsent: unsent, // If this variable is set to 0, then it will show leads that have been marked as seen (old leads)
|
unsent: unsent, // If this variable is set to 0, then it will show leads that have been marked as seen (old leads)
|
||||||
test: test, // If this is removed or set to 0, then all leads that are returned would be marked as seen. This allows you to only fetch new leads
|
test: test, // If this is removed or set to 0, then all leads that are returned would be marked as seen. This allows you to only fetch new leads
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await response.json();
|
if (!response.ok) {
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw new Error(`Keystone HTTP Error ${response.status} (${response.statusText}): ${ errorText }`);
|
||||||
|
}
|
||||||
|
|
||||||
if (!response.ok || !Array.isArray(result?.data)) {
|
const result = await response.json();
|
||||||
console.log('API response empty or invalid: ', result.message || response.statusText);
|
|
||||||
|
if (!Array.isArray(result?.data)) {
|
||||||
|
console.log('API response empty or invalid: ', result?.message || 'No data rray found');
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ async function createHubspotContacts(leadContactsPayload) {
|
|||||||
for (let i = 0; i < leadContactsPayload.length; i += 100) {
|
for (let i = 0; i < leadContactsPayload.length; i += 100) {
|
||||||
let payloadsBatch = leadContactsPayload.slice(i, i + 100);
|
let payloadsBatch = leadContactsPayload.slice(i, i + 100);
|
||||||
let payloadTest = [leadContactsPayload[0]];
|
let payloadTest = [leadContactsPayload[0]];
|
||||||
const creationContacts = await hubspot.upsertBatchCRMRecord('contacts', payloadsBatch);
|
const creationContacts = await hubspot.upsertBatchCRMRecord('contacts', payloadTest);
|
||||||
if (creationContacts) {
|
if (creationContacts) {
|
||||||
console.log('Batch successfully created!');
|
console.log('Batch successfully created!');
|
||||||
console.log(JSON.stringify(creationContacts, null, 2));
|
console.log(JSON.stringify(creationContacts, null, 2));
|
||||||
|
|||||||
Reference in new issue
Block a user