-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.js
More file actions
66 lines (54 loc) · 1.78 KB
/
source.js
File metadata and controls
66 lines (54 loc) · 1.78 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
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
const ninNum = args[0] ?? "63184876213";
const firstName = args[1] ?? "Bunch";
const lastName = args[2] ?? "Dillon";
const voterMatricNo = args[3];
const clientId = secrets.VERIFYME_CLIENT_ID;
const authKey = secrets.VERIFYME_TESTKEY;
if (!authKey || !clientId) {
console.error("Secret key or clientId not found!");
throw Error("Secret key or clientId not found!");
}
if (!ninNum || !firstName || !lastName) {
console.error("One or more of nin, firstName and lastname is null", ninNum, firstName, lastName);
throw Error("Request failed: One or more of nin, firstName and lastname is null");
}
console.log("Starting auth post")
// Execute the API request (Promise)
const authApiResponse = await Functions.makeHttpRequest({
method: "POST",
url: "https://api.qoreid.com/token",
data: {
"secret": authKey,
"clientId": clientId
},
headers: {
"accept": "text/plain",
"content-type": "application/json"
}
});
if (authApiResponse.error) {
console.error(authApiResponse.error);
throw Error("Request failed");
}
console.log("Starting nin post", authApiResponse.data);
// Execute the API request (Promise)
const apiResponse = await Functions.makeHttpRequest({
method: "POST",
url: `https://api.qoreid.com/v1/ng/identities/nin/${ninNum}`,
headers: {
"accept": "application/json",
"content-type": "application/json",
"authorization": `Bearer ${authApiResponse.data.accessToken}`
},
data: {
"firstname": firstName,
"lastname": lastName
}
});
if (apiResponse.error) {
console.error(apiResponse.error);
throw Error("Request failed");
}
const { data } = apiResponse;
console.log('API response data:', JSON.stringify(data, null, 2));
return Functions.encodeString(voterMatricNo);