-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetOwners.js
25 lines (22 loc) · 963 Bytes
/
getOwners.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const {fs, path, dataCurrentPath, dataConfPath} = require('./lib/pathsAndFS');
const { hubspotClient } = require('./lib/hubspotClient');
async function getOwners() {
const body = await hubspotClient.crm.owners.ownersApi.getPage();
const owners = body.results;
fs.writeFileSync(path.resolve(dataCurrentPath, 'owners.json'), JSON.stringify(owners, null, 2));
console.log('Got ' + owners.length + ' owners');
// init conf if not exists
const ownersMapPath = path.resolve(dataConfPath, 'ownersMap.json');
const initConfMap = [];
if (fs.existsSync(ownersMapPath)) {
const current = require(ownersMapPath);
initConfMap.push(...current);
}
for (const owner of owners) {
if (initConfMap.find((i) => owner.id === i.hubspot?.id)) continue;
initConfMap.push({copper: null, hubspot: owner});
console.log('Added to conf: ' + owner.email);
}
fs.writeFileSync(ownersMapPath, JSON.stringify(initConfMap, null, 2));
};
getOwners();