#!/usr/bin/env node
/**
* Simple test script to diagnose Projects endpoint issues
*/
const { config } = require('dotenv');
const { AutotaskService } = require('../dist/services/autotask.service.js');
const winston = require('winston');
// Load environment variables
config();
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.Console()
]
});
async function testProjectsEndpoint() {
console.log('π Testing Projects endpoint issues...\n');
// Create the service
const serviceConfig = {
autotask: {
username: process.env.AUTOTASK_USERNAME,
secret: process.env.AUTOTASK_SECRET,
integrationCode: process.env.AUTOTASK_INTEGRATION_CODE
}
};
const autotaskService = new AutotaskService(serviceConfig, logger);
try {
console.log('π‘ Initializing service...');
await autotaskService.initialize();
console.log('β
Service initialized successfully\n');
// Test 1: Simple search projects call to get exact error
console.log('π Test 1: Simple searchProjects call...');
try {
const projects = await autotaskService.searchProjects({ pageSize: 1 });
console.log('β
Projects search succeeded!');
console.log(`Found ${projects.length} projects`);
if (projects.length > 0) {
console.log('First project:', JSON.stringify(projects[0], null, 2));
}
} catch (error) {
console.log('β Projects search failed:', error.message);
console.log('Status:', error.response?.status);
console.log('Response data:', JSON.stringify(error.response?.data, null, 2));
}
// Test 2: Compare with working companies endpoint
console.log('\nπ Test 2: Compare with working companies...');
try {
const companies = await autotaskService.searchCompanies({ pageSize: 1 });
console.log('β
Companies search works!');
console.log(`Found ${companies.length} companies`);
} catch (error) {
console.log('β Companies search also failed:', error.message);
}
} catch (error) {
console.error('β Test setup failed:', error.message);
}
}
testProjectsEndpoint()
.then(() => {
console.log('\nβ
Test completed');
process.exit(0);
})
.catch((error) => {
console.error('β Test failed with error:', error);
process.exit(1);
});