diff --git a/cfg/hubspot.json b/cfg/hubspot.json index 2117359..01c26c8 100644 --- a/cfg/hubspot.json +++ b/cfg/hubspot.json @@ -1,8 +1,8 @@ { "token_type": "bearer", - "refresh_token": "dfdb8172-1072-4a95-8122-6f4be5dbcbaf", - "access_token": "CPDM2euDNBInQlNQMl8kQEwrAhoACAcCAhICEgkEHgEBAQEBAQEbAQIBLh4BIAEgGI-0ogEgopooKMKUazIUAyadDK38t_Nd7afu92XPlJWNIAo6a0JTUDJfJEBMKwNcAAeOAgTLAhP1AgaYAwejAwaBBQaJBggTGRobH4oBiwGQAbsB3gH6AfsB_AGVApYCtgLHAv8DgASEBIUEowSkBKUEpwSoBN0E4QbiBuMGlZoFrO8F3_cFgvkFg_kF_PUIQhSC4VGhsI_4_JW1pwepVd_QSHEyGEoDbmExUgBaAGAAaKKaKHAAeAA", - "hub_id": 2660879, + "refresh_token": "na1-c9d6-ac6a-4cf7-900e-fbf129e4d304", + "access_token": "CJO3xvSDNBInQlNQMl8kQEwrAhoACAcCAhICEgkEHgEBAQEBAQEbAQIBLh4BIAEgGLSDjwQgopooKMKUazIU7Voj7R3fYKocVet-YlLBF5eMWBg6aUJTUDJfJEBMKwNbAAeOAgTLAhP1AgaYAwejAwaBBQaJBggTGRobH4oBiwGQAbsB3gH6AfsB_AGVApYCtgLHAv8DgASEBIUEowSlBKcEqATdBOEG4gbjBpWaBazvBd_3BYL5BYP5Bfz1CEIUJXR4UFjJB7TIP67bXBkIRps5j5pKA25hMVIAWgBgAGiimihwAHgA", + "hub_id": 8634804, "scopes": [ "crm.lists.read", "crm.objects.deals.read", diff --git a/src/fetchLeadsFromKeystone.js b/src/fetchLeadsFromKeystone.js index ddbd35e..5905f1f 100644 --- a/src/fetchLeadsFromKeystone.js +++ b/src/fetchLeadsFromKeystone.js @@ -26,6 +26,9 @@ async function getLeads(lastRunDate, currentDate, unsent, test) { const result = await response.json(); + console.log(JSON.stringify(result,null,2)); + + if (!Array.isArray(result?.data)) { console.log('API response empty or invalid: ', result?.message || 'No data array found'); return []; diff --git a/src/hubspotConnector.js b/src/hubspotConnector.js index 9a30cbe..673db46 100644 --- a/src/hubspotConnector.js +++ b/src/hubspotConnector.js @@ -51,7 +51,7 @@ let fields = { return targetCountry.toUpperCase(); },*/ corso_keystone: (lead) => lead.programList?.join('; ') ?? '', - leadsource: () => 'keystone' + leadsource: () => 'Keystone' }; function mapFields(lead) { @@ -134,7 +134,10 @@ async function runConnector() { //isDryRun = true; // here we consider the last time we ran the connector let lastRunDate = ''; // we will use this to simplify the management of the leads - let currentDate = new Date().toISOString(); // we consider only the date of the current datestamp + let date = new Date(); + date.setDate(date.getDate() + 1); + let tomorrowDate = date.toISOString(); // we consider only the date of the current datestamp + let currentDate = new Date().toISOString(); if (fs.existsSync(FILE_PATH)) { const file = fs.readFileSync(FILE_PATH, 'utf8'); lastRunDate = JSON.parse(file).lastRun; @@ -148,16 +151,17 @@ async function runConnector() { } try { - console.log('Retrieving data from Keystone...', lastRunDate, currentDate, isDryRun ); + console.log('Retrieving data from Keystone...', lastRunDate, tomorrowDate, isDryRun ); // getLeads(lastRunDate, currentDate, unsent, test) const unsetValue = 0; const testValue = isDryRun ? 1 : 0; - const leads = await getLeads(lastRunDate, currentDate, unsetValue, testValue); + const leads = await getLeads(lastRunDate, tomorrowDate, unsetValue, testValue); if (!leads.length) { console.log('No data retrieved.'); return; } + console.log('New leads:', leads.length); // here we save the last time we ran the connector if (!isDryRun) {