74 lines
2.7 KiB
JavaScript
74 lines
2.7 KiB
JavaScript
// Test NocoDB API directly to debug the issue
|
|
const axios = require('axios');
|
|
require('dotenv').config();
|
|
|
|
async function testNocoDB() {
|
|
const apiUrl = process.env.NOCODB_API_URL;
|
|
const apiToken = process.env.NOCODB_API_TOKEN;
|
|
const projectId = process.env.NOCODB_PROJECT_ID || 'pp1ijipzj121aqq';
|
|
const shiftSignupsSheetId = process.env.NOCODB_SHIFT_SIGNUPS_SHEET || 'mocxv7kzcvyo4aa';
|
|
|
|
const client = axios.create({
|
|
baseURL: apiUrl,
|
|
timeout: 10000,
|
|
headers: {
|
|
'xc-token': apiToken,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
// Test 1: Try to get table info
|
|
console.log('Test 1: Getting table info...');
|
|
try {
|
|
const url = `/db/data/v1/${projectId}/${shiftSignupsSheetId}?limit=1`;
|
|
console.log('Request URL:', apiUrl + url);
|
|
const response = await client.get(url);
|
|
console.log('Table info response:', JSON.stringify(response.data, null, 2));
|
|
} catch (error) {
|
|
console.error('Error getting table info:', error.response?.data || error.message);
|
|
}
|
|
|
|
// Test 2: Try to create a minimal record
|
|
console.log('\nTest 2: Creating minimal record...');
|
|
try {
|
|
const testData = {
|
|
'Shift ID': 1,
|
|
'User Email': 'test@example.com',
|
|
'User Name': 'Test User',
|
|
'Status': 'Confirmed'
|
|
};
|
|
|
|
console.log('Test data:', JSON.stringify(testData, null, 2));
|
|
|
|
const url = `/db/data/v1/${projectId}/${shiftSignupsSheetId}`;
|
|
console.log('Create URL:', apiUrl + url);
|
|
|
|
const response = await client.post(url, testData);
|
|
console.log('Create response:', JSON.stringify(response.data, null, 2));
|
|
} catch (error) {
|
|
console.error('Error creating record:');
|
|
console.error('Status:', error.response?.status);
|
|
console.error('Data:', JSON.stringify(error.response?.data, null, 2));
|
|
console.error('Headers:', JSON.stringify(error.response?.headers, null, 2));
|
|
}
|
|
|
|
// Test 3: Check what table fields exist
|
|
console.log('\nTest 3: Getting table schema...');
|
|
try {
|
|
const schemaUrl = `/db/meta/projects/${projectId}/tables`;
|
|
const response = await client.get(schemaUrl);
|
|
const tables = response.data.list || [];
|
|
const signupsTable = tables.find(t => t.id === shiftSignupsSheetId);
|
|
if (signupsTable) {
|
|
console.log('Signups table columns:');
|
|
signupsTable.columns?.forEach(col => {
|
|
console.log(` - ${col.title} (${col.column_name}) - ${col.uidt} - PK: ${col.pk}`);
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Error getting schema:', error.response?.data || error.message);
|
|
}
|
|
}
|
|
|
|
testNocoDB().catch(console.error);
|