-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-api.js
More file actions
34 lines (29 loc) · 998 Bytes
/
Copy pathtest-api.js
File metadata and controls
34 lines (29 loc) · 998 Bytes
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
// Simple test to verify API key access
require('dotenv').config();
const fetch = require('node-fetch');
async function testApi() {
const apiKey = process.env.CODA_API_KEY;
console.log(`Using API key: ${apiKey ? apiKey.substring(0, 5) + '...' + apiKey.substring(apiKey.length - 4) : 'Not found'}`);
try {
// First, try to list all documents
console.log("Testing API access - listing documents");
const response = await fetch('https://coda.io/apis/v1/docs', {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
});
const data = await response.text();
console.log(`Response status: ${response.status}`);
console.log(`Response body: ${data}`);
if (!response.ok) {
console.error("API access failed");
} else {
console.log("API access successful");
}
} catch (error) {
console.error(`Error accessing API: ${error.message}`);
}
}
testApi();