-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-consumer.ts
More file actions
39 lines (30 loc) · 1.1 KB
/
get-consumer.ts
File metadata and controls
39 lines (30 loc) · 1.1 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
import { Api, Consumer } from '../src';
import * as fs from 'fs';
import * as path from 'path';
/**
* Example: Get consumer information
*
* This example shows how to retrieve consumer information by phone number.
*/
async function main() {
try {
// Enable sandbox mode
Api.setSandbox(true);
// Load authentication keys
const authFilePath = path.join(__dirname, 'authentication.json');
const authData = JSON.parse(fs.readFileSync(authFilePath, 'utf-8'));
Api.setPublicKey(authData.public_key);
Api.setPrivateKey(authData.private_key);
Api.setKeyId(authData.key_id);
// Replace with an actual phone number (format: +39xxxxxxxxxx)
const phoneNumber = '+393331234567';
console.log(`Fetching consumer ${phoneNumber}...`);
const consumer = await Consumer.get(phoneNumber);
console.log('Consumer details:');
console.log(JSON.stringify(consumer, null, 2));
} catch (error) {
console.error('Error:', error instanceof Error ? error.message : String(error));
process.exit(1);
}
}
main();