Skip to content

Instantly share code, notes, and snippets.

@twosdai
Created February 13, 2025 17:51
Show Gist options
  • Save twosdai/6b11411b6b4844facb09e8502327b970 to your computer and use it in GitHub Desktop.
Save twosdai/6b11411b6b4844facb09e8502327b970 to your computer and use it in GitHub Desktop.
const fetch = require('cross-fetch');
async function fetchAndCheckLeadsForTrackingmore(url) {
let offset = 0;
const limit = 100;
let totalLeads = Infinity; // Initial dummy value
while (offset < totalLeads) {
try {
const response = await fetch(`${url}&offset=${offset}&limit=${limit}`);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const json = await response.json();
totalLeads = parseInt(json.total_leads, 10);
json.data.forEach(item => {
const lead = item.lead;
const customFields = lead.custom_fields;
if (customFields) {
// Define the template fields to check
const templateFields = [
'Template_1_Output',
'Template_2_Output',
'Template_3_Output'
];
templateFields.forEach(field => {
const fieldValue = customFields[field];
if (
typeof fieldValue === 'string' &&
fieldValue.toLowerCase().includes('client_name')
) {
console.log(
`Lead ${lead.email} (Name: ${lead.first_name} ${lead.last_name}) contains "client_name" in ${field}`
);
}
});
}
});
offset += limit;
} catch (error) {
console.error(`Error fetching leads at offset ${offset}:`, error);
break;
}
}
}
// Use the API URL for campaign 1418171
const campaignUrl = 'https://server.smartlead.ai/api/v1/campaigns/:id/leads?api_key=secret';
fetchAndCheckLeadsForTrackingmore(campaignUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment