-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtest_d-id.js
33 lines (27 loc) · 870 Bytes
/
test_d-id.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
const fetch = require('node-fetch');
const base64 = require('base-64');
const fs = require('fs');
async function getDidCredits(apiKey) {
const url = "https://api.d-id.com/credits";
const authString = apiKey + ":";
const base64AuthString = base64.encode(authString);
const headers = {
"accept": "application/json",
"Authorization": `Basic ${base64AuthString}`
};
const response = await fetch(url, { headers });
const data = await response.json();
return data;
}
async function main() {
try {
// Read the API key from api.json file
const apiKeyJson = JSON.parse(fs.readFileSync('api.json', 'utf8'));
const apiKey = apiKeyJson.key;
const didCredits = await getDidCredits(apiKey);
console.log("Response:", didCredits);
} catch (error) {
console.error("Error:", error);
}
}
main();