test-api-debug.jsā¢6.13 kB
#!/usr/bin/env node
/**
* API Debug Test - Investigate the 500 error
*/
import { readFileSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
const currentDir = dirname(fileURLToPath(import.meta.url));
const tokenPath = resolve(currentDir, 'correct-jwt-new.txt');
const jwtToken = readFileSync(tokenPath, 'utf8').trim();
async function debugAPI() {
console.log('š API Debug Test\n');
// First, let's verify our JWT token
console.log('1ļøā£ JWT Token Info:');
console.log(` - Length: ${jwtToken.length} characters`);
console.log(` - Starts with: ${jwtToken.substring(0, 50)}...`);
console.log(` - Contains NEsta: ${jwtToken.includes('NEsta')}`);
console.log(` - Contains WEJLam: ${jwtToken.includes('WEJLam')}`);
// Parse JWT to check expiration
try {
const [header, payload, signature] = jwtToken.split('.');
const decodedPayload = JSON.parse(Buffer.from(payload, 'base64').toString());
console.log(` - Issued: ${new Date(decodedPayload.iat * 1000).toISOString()}`);
console.log(` - Expires: ${new Date(decodedPayload.exp * 1000).toISOString()}`);
console.log(` - Email: ${decodedPayload.email}`);
console.log(` - Roles: ${decodedPayload.role.join(', ')}`);
} catch (e) {
console.log(' - Failed to decode JWT');
}
const baseURL = "https://api.digitalpages.com.br";
const projectUID = "36c92686-c494-ec11-a22a-dc984041c95d";
// Test 1: Try search endpoint (original)
console.log('\n2ļøā£ Testing Search Endpoint:');
try {
const searchURL = `${baseURL}/storage/v1.0/search?project_uid=${projectUID}&limit=1`;
console.log(` - URL: ${searchURL}`);
const searchResponse = await fetch(searchURL, {
method: 'GET',
headers: {
'Authorization': `Bearer ${jwtToken}`,
'User-Agent': 'EuConquisto-MCP-Debug/1.0',
'Accept': 'application/json'
}
});
console.log(` - Status: ${searchResponse.status} ${searchResponse.statusText}`);
const searchData = await searchResponse.text();
console.log(` - Response: ${searchData}`);
} catch (error) {
console.log(` - Error: ${error.message}`);
}
// Test 2: Try without project_uid
console.log('\n3ļøā£ Testing Without Project UID:');
try {
const simpleURL = `${baseURL}/storage/v1.0/search?limit=1`;
console.log(` - URL: ${simpleURL}`);
const simpleResponse = await fetch(simpleURL, {
method: 'GET',
headers: {
'Authorization': `Bearer ${jwtToken}`,
'User-Agent': 'EuConquisto-MCP-Debug/1.0',
'Accept': 'application/json'
}
});
console.log(` - Status: ${simpleResponse.status} ${simpleResponse.statusText}`);
const simpleData = await simpleResponse.text();
console.log(` - Response: ${simpleData}`);
} catch (error) {
console.log(` - Error: ${error.message}`);
}
// Test 3: Try the content endpoint directly (from Claude Desktop's discovery)
console.log('\n4ļøā£ Testing Content Endpoint (GET):');
try {
const contentURL = `${baseURL}/storage/v1.0/content?manual_project_uid=${projectUID}`;
console.log(` - URL: ${contentURL}`);
const contentResponse = await fetch(contentURL, {
method: 'GET',
headers: {
'Authorization': `Bearer ${jwtToken}`,
'User-Agent': 'EuConquisto-MCP-Debug/1.0',
'Accept': 'application/json'
}
});
console.log(` - Status: ${contentResponse.status} ${contentResponse.statusText}`);
const contentData = await contentResponse.text();
console.log(` - Response: ${contentData.substring(0, 200)}...`);
} catch (error) {
console.log(` - Error: ${error.message}`);
}
// Test 4: Try a simple OPTIONS request to check CORS
console.log('\n5ļøā£ Testing OPTIONS (CORS Check):');
try {
const optionsURL = `${baseURL}/storage/v1.0/content`;
console.log(` - URL: ${optionsURL}`);
const optionsResponse = await fetch(optionsURL, {
method: 'OPTIONS',
headers: {
'Origin': 'https://composer.euconquisto.com',
'Access-Control-Request-Method': 'PUT',
'Access-Control-Request-Headers': 'authorization,content-type'
}
});
console.log(` - Status: ${optionsResponse.status} ${optionsResponse.statusText}`);
console.log(` - CORS Headers:`);
console.log(` - Allow-Origin: ${optionsResponse.headers.get('access-control-allow-origin')}`);
console.log(` - Allow-Methods: ${optionsResponse.headers.get('access-control-allow-methods')}`);
console.log(` - Allow-Headers: ${optionsResponse.headers.get('access-control-allow-headers')}`);
} catch (error) {
console.log(` - Error: ${error.message}`);
}
// Test 5: Try to decode the actual working URL from the browser
console.log('\n6ļøā£ Testing Known Working Pattern:');
console.log(' - In browser, compositions are saved via:');
console.log(' PUT /storage/v1.0/content?uid={UID}&manual_project_uid={PROJECT_UID}');
console.log(' - With multipart/form-data containing composition.rdpcomposer file');
console.log(' - This suggests we need to use PUT with multipart, not GET');
console.log('\nš Summary:');
console.log(' - The 500 error might be because the search endpoint expects different parameters');
console.log(' - Or the API might require specific headers/format we\'re missing');
console.log(' - The JWT token appears valid and not expired');
console.log(' - We should try the exact pattern used by the browser');
}
debugAPI().catch(console.error);