some fixes
This commit is contained in:
1 parent
57c28b2806
commit
f21a572f45
3 files changed
+14
-7
No files matched your search
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"token_type": "bearer",
|
"token_type": "bearer",
|
||||||
"refresh_token": "dfdb8172-1072-4a95-8122-6f4be5dbcbaf",
|
"refresh_token": "na1-c9d6-ac6a-4cf7-900e-fbf129e4d304",
|
||||||
"access_token": "CPDM2euDNBInQlNQMl8kQEwrAhoACAcCAhICEgkEHgEBAQEBAQEbAQIBLh4BIAEgGI-0ogEgopooKMKUazIUAyadDK38t_Nd7afu92XPlJWNIAo6a0JTUDJfJEBMKwNcAAeOAgTLAhP1AgaYAwejAwaBBQaJBggTGRobH4oBiwGQAbsB3gH6AfsB_AGVApYCtgLHAv8DgASEBIUEowSkBKUEpwSoBN0E4QbiBuMGlZoFrO8F3_cFgvkFg_kF_PUIQhSC4VGhsI_4_JW1pwepVd_QSHEyGEoDbmExUgBaAGAAaKKaKHAAeAA",
|
"access_token": "CJO3xvSDNBInQlNQMl8kQEwrAhoACAcCAhICEgkEHgEBAQEBAQEbAQIBLh4BIAEgGLSDjwQgopooKMKUazIU7Voj7R3fYKocVet-YlLBF5eMWBg6aUJTUDJfJEBMKwNbAAeOAgTLAhP1AgaYAwejAwaBBQaJBggTGRobH4oBiwGQAbsB3gH6AfsB_AGVApYCtgLHAv8DgASEBIUEowSlBKcEqATdBOEG4gbjBpWaBazvBd_3BYL5BYP5Bfz1CEIUJXR4UFjJB7TIP67bXBkIRps5j5pKA25hMVIAWgBgAGiimihwAHgA",
|
||||||
"hub_id": 2660879,
|
"hub_id": 8634804,
|
||||||
"scopes": [
|
"scopes": [
|
||||||
"crm.lists.read",
|
"crm.lists.read",
|
||||||
"crm.objects.deals.read",
|
"crm.objects.deals.read",
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ async function getLeads(lastRunDate, currentDate, unsent, test) {
|
|||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
|
console.log(JSON.stringify(result,null,2));
|
||||||
|
|
||||||
|
|
||||||
if (!Array.isArray(result?.data)) {
|
if (!Array.isArray(result?.data)) {
|
||||||
console.log('API response empty or invalid: ', result?.message || 'No data array found');
|
console.log('API response empty or invalid: ', result?.message || 'No data array found');
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ let fields = {
|
|||||||
return targetCountry.toUpperCase();
|
return targetCountry.toUpperCase();
|
||||||
},*/
|
},*/
|
||||||
corso_keystone: (lead) => lead.programList?.join('; ') ?? '',
|
corso_keystone: (lead) => lead.programList?.join('; ') ?? '',
|
||||||
leadsource: () => 'keystone'
|
leadsource: () => 'Keystone'
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapFields(lead) {
|
function mapFields(lead) {
|
||||||
@@ -134,7 +134,10 @@ async function runConnector() {
|
|||||||
//isDryRun = true;
|
//isDryRun = true;
|
||||||
// here we consider the last time we ran the connector
|
// here we consider the last time we ran the connector
|
||||||
let lastRunDate = ''; // we will use this to simplify the management of the leads
|
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)) {
|
if (fs.existsSync(FILE_PATH)) {
|
||||||
const file = fs.readFileSync(FILE_PATH, 'utf8');
|
const file = fs.readFileSync(FILE_PATH, 'utf8');
|
||||||
lastRunDate = JSON.parse(file).lastRun;
|
lastRunDate = JSON.parse(file).lastRun;
|
||||||
@@ -148,16 +151,17 @@ async function runConnector() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Retrieving data from Keystone...', lastRunDate, currentDate, isDryRun );
|
console.log('Retrieving data from Keystone...', lastRunDate, tomorrowDate, isDryRun );
|
||||||
// getLeads(lastRunDate, currentDate, unsent, test)
|
// getLeads(lastRunDate, currentDate, unsent, test)
|
||||||
const unsetValue = 0;
|
const unsetValue = 0;
|
||||||
const testValue = isDryRun ? 1 : 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) {
|
if (!leads.length) {
|
||||||
console.log('No data retrieved.');
|
console.log('No data retrieved.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log('New leads:', leads.length);
|
||||||
|
|
||||||
// here we save the last time we ran the connector
|
// here we save the last time we ran the connector
|
||||||
if (!isDryRun) {
|
if (!isDryRun) {
|
||||||
|
|||||||
Reference in new issue
Block a user