-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
86 lines (67 loc) · 2.06 KB
/
index.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//include required modules
const jwt = require('jsonwebtoken');
const config = require('./config');
const rp = require('request-promise');
const fs=require('fs');
meetid = MEETING-ID //Change meetID
async function apiCall(userData){
for(const user of userData){
const payload = {
iss: config.APIKey,
exp: ((new Date()).getTime() + 2000)
};
const token = jwt.sign(payload, config.APISecret);
var options = {
uri: "https://api.zoom.us/v2/meetings/"+meetid+"/registrants",
auth: {
'bearer': token
},
headers: {
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
},
body:{
"email": user.email,
"first_name": user.first_name,
"last_name": user.last_name
},
json: true,
method: 'POST'
};
await rp(options)
.then(function (response) {
console.log(response);
})
.catch(function (err) {
try {
fs.appendFileSync('error.txt',err.toString()+'\n'+'Data of the user which caused the error is ->'+'first_name:'+user.first_name+", last_name:"+user.last_name+", email:"+user.email+'\n\n')
} catch (error) {
console.log(error);
}
});
}
}
function csvJSON(csv){
var lines=csv.split("\n");
var result = [];
var headers=lines[0].split(",");
for(var i=1;i<lines.length;i++){
var obj = {};
var currentline=lines[i].split(",");
for(var j=0;j<headers.length;j++){
obj[headers[j]] = currentline[j];
}
if(obj[headers[0]]==='')
continue
result.push(obj);
}
return result;
}
let data
try {
data = fs.readFileSync('registrants.csv', 'utf8')
} catch (err) {
console.error(err)
}
const userData=csvJSON(data);
apiCall(userData);