-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-debug-api.mjs
More file actions
84 lines (70 loc) · 2.44 KB
/
Copy pathtest-debug-api.mjs
File metadata and controls
84 lines (70 loc) · 2.44 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/**
* Debug test to check what's happening with the API
*/
import dotenv from 'dotenv';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
// Load environment variables
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
dotenv.config({ path: join(__dirname, '.env.local') });
const apiKey = process.env.WHOP_API_KEY;
console.log('\n🔍 Debugging Whop API Access\n');
console.log('='.repeat(50));
// Test 1: Check if we can access ANY endpoint
console.log('\n1️⃣ Testing basic API access (user info)...');
try {
const userResponse = await fetch('https://api.whop.com/api/v1/users/@me', {
headers: {
'Authorization': `Bearer ${apiKey}`,
}
});
console.log(' Status:', userResponse.status);
const userData = await userResponse.json();
console.log(' Response:', JSON.stringify(userData, null, 2).substring(0, 300));
} catch (e) {
console.log(' Error:', e.message);
}
// Test 2: Check app info
console.log('\n2️⃣ Testing app access...');
try {
const appResponse = await fetch(`https://api.whop.com/api/v1/apps/${process.env.NEXT_PUBLIC_WHOP_APP_ID}`, {
headers: {
'Authorization': `Bearer ${apiKey}`,
}
});
console.log(' Status:', appResponse.status);
const appData = await appResponse.json();
console.log(' Response:', JSON.stringify(appData, null, 2).substring(0, 300));
} catch (e) {
console.log(' Error:', e.message);
}
// Test 3: Try different product endpoint variations
console.log('\n3️⃣ Testing product endpoint variations...');
const variations = [
'https://api.whop.com/api/v1/products?company_id=biz_2T7tC1fnFVo6d4',
'https://api.whop.com/api/v2/products?company_id=biz_2T7tC1fnFVo6d4',
'https://api.whop.com/api/v1/companies/biz_2T7tC1fnFVo6d4/products',
'https://api.whop.com/api/v1/companies/biz_2T7tC1fnFVo6d4/access_passes',
];
for (const url of variations) {
console.log(`\n Testing: ${url}`);
try {
const response = await fetch(url, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Accept': 'application/json',
}
});
console.log(` Status: ${response.status}`);
if (response.status !== 404) {
const text = await response.text();
console.log(` Response: ${text.substring(0, 150)}`);
}
} catch (e) {
console.log(` Error: ${e.message}`);
}
}
console.log('\n' + '='.repeat(50));
console.log('✅ Debug complete!\n');