forked from domdomegg/airtable-mcp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-datasheet-by-name.js
More file actions
67 lines (52 loc) · 2.24 KB
/
test-datasheet-by-name.js
File metadata and controls
67 lines (52 loc) · 2.24 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
#!/usr/bin/env node
import { AITableService } from './dist/aitableService.js';
// Get default space ID from environment variables
const defaultSpaceId = process.env.SPACE || '';
const apiKey = process.env.AITABLE_API_KEY || '';
if (!apiKey) {
console.error('ERROR: No API key found. Please set the AITABLE_API_KEY environment variable.');
process.exit(1);
}
// Helper function to display results nicely
function displayResults(title, data) {
console.log(`\n=== ${title} ===`);
console.log(JSON.stringify(data, null, 2));
console.log('='.repeat(40));
}
async function testGetDatasheetByName() {
try {
console.log('Testing getDatasheetRecordsByName method...');
// Create the AITableService instance
const aitableService = new AITableService(apiKey);
// Get a list of datasheets first to see what's available
console.log('Getting all available datasheets first...');
const spaceId = defaultSpaceId;
const datasheets = await aitableService.getAllDatasheets(spaceId);
console.log(`\nFound ${datasheets.length} datasheets in space ${spaceId}:`);
datasheets.forEach((ds, index) => {
console.log(`${index + 1}. ${ds.name} (Path: ${ds.path})`);
});
// Test getting records directly by datasheet name
const datasheetName = 'CRM'; // Try to get the CRM datasheet
console.log(`\nTrying to get records from datasheet "${datasheetName}" directly by name...`);
try {
const records = await aitableService.getDatasheetRecordsByName(
spaceId,
datasheetName,
{ maxRecords: 10 }
);
console.log(`\nSuccess! Retrieved ${records.length} records from "${datasheetName}" datasheet:`);
displayResults(`${datasheetName} Records`, records);
} catch (error) {
console.error(`\nFailed to get records from "${datasheetName}" datasheet:`, error.message);
// Suggest some available datasheets to try instead
console.log('\nAvailable datasheets you could try instead:');
datasheets.slice(0, 5).forEach(ds => console.log(` - ${ds.name}`));
}
console.log('\n✅ Test completed');
} catch (error) {
console.error('Error testing datasheet by name access:', error);
}
}
// Run the test
testGetDatasheetByName();