-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetAllMembers.js
More file actions
29 lines (24 loc) · 1.12 KB
/
getAllMembers.js
File metadata and controls
29 lines (24 loc) · 1.12 KB
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
26
27
28
29
const api = require('./api');
async function main () {
if (!process.env.TRIGGERZ_CLIENT_ID || !process.env.TRIGGERZ_CLIENT_SECRET) {
console.error('ERROR: Both environment variables TRIGGERZ_CLIENT_ID and TRIGGERZ_CLIENT_SECRET must be set before running this demo.');
return;
}
const host = process.env.TRIGGERZ_API_HOST || 'https://api.triggerz.com';
const accessToken = await api.authenticating(process.env.TRIGGERZ_CLIENT_ID, process.env.TRIGGERZ_CLIENT_SECRET);
const memberListStringResponse = await api.getting(host, 'member/list', accessToken);
const memberListResponse = JSON.parse(memberListStringResponse);
const emailList = Object.keys(memberListResponse.memberByEmail);
const memberDetailByEmail = {};
for (const email of emailList) {
const memberStringResponse = await api.getting(host, `member/byEmail/${email}`, accessToken);
memberDetailByEmail[email] = JSON.parse(memberStringResponse);
}
console.log(JSON.stringify(memberDetailByEmail, null, 2));
}
const isCli = require.main === module;
if (isCli) {
main().catch(err => console.error(err.message));
} else {
module.exports = main;
}