-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.js
More file actions
46 lines (39 loc) · 1.28 KB
/
test_api.js
File metadata and controls
46 lines (39 loc) · 1.28 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
// Test API script
import fetch from 'node-fetch';
// Replace this with your actual token from the browser localStorage
const token = process.argv[2] || 'YOUR_TOKEN_HERE';
async function testAPI() {
try {
console.log('Testing get profiles API with token:', token.substring(0, 20) + '...');
const response = await fetch('http://localhost:5001/api/profiles', {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log('API Response:', JSON.stringify(data, null, 2));
if (data.success) {
console.log(`Found ${data.count} child profiles`);
if (data.data && data.data.length > 0) {
data.data.forEach((profile, index) => {
console.log(`Profile ${index + 1}:`);
console.log(` ID: ${profile.id}`);
console.log(` Name: "${profile.name}"`);
console.log(` Age: ${profile.age}`);
});
}
} else {
console.error('API Error:', data.error);
}
} catch (error) {
console.error('Error testing API:', error);
}
}
testAPI();
/*
To run this script:
1. Copy your token from the browser's localStorage
2. Run: node --experimental-modules test_api.js YOUR_TOKEN
*/