initial commit
This commit is contained in:
commit
a60c8ee04d
7 files changed
+2181
No files matched your search
@@ -0,0 +1,44 @@
|
||||
const path = require('path');
|
||||
|
||||
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
|
||||
|
||||
// this function retrieve the users' data from Keystone
|
||||
async function getLeads() {
|
||||
try {
|
||||
const response = await fetch('https://smarthub.keystoneacademic.com/api/rest/getLead', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-api-key': process.env.KEYSTONE_API_KEY,
|
||||
'Accept': 'application/json',
|
||||
'Content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
unsent: 1, // If this variable is set to 0, then it will show leads that have been marked as seen (old leads)
|
||||
test: 1, // 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 (!Array.isArray(result?.data)) {
|
||||
console.log('API response empty or invalid: ', result);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const lead of result.data) {
|
||||
console.log('ID: ', lead.id);
|
||||
console.log('First Name: ', lead.firstname);
|
||||
console.log('Last Name: ', lead.lastname);
|
||||
console.log('Email: ', lead.contact?.email ?? 'N/D');
|
||||
console.log('Phone: ', lead.contact?.phone ?? 'N/D');
|
||||
console.log('Program: ', lead.program?.name ?? 'N/D');
|
||||
console.log('--------------------------');
|
||||
}
|
||||
return result.data || [];
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Error fetching the data: ", error);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getLeads };
|
||||
Reference in new issue
Block a user