-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtest_d-id.js
More file actions
38 lines (32 loc) · 1.02 KB
/
test_d-id.js
File metadata and controls
38 lines (32 loc) · 1.02 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
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);
// Extracting just the 'remaining' and 'total' values
const creditsSummary = {
remaining: didCredits.remaining,
total: didCredits.total
};
console.log("Credits Summary:", creditsSummary);
} catch (error) {
console.error("Error:", error);
}
}
main();