1require('dotenv').config();
2const MeshCentralAPI = require('./lib/meshcentral-api.js');
8 console.log('🔧 Testing MeshCentral API...\n');
9 console.log('URL:', process.env.MESHCENTRAL_URL);
10 console.log('Username:', process.env.MESHCENTRAL_USERNAME);
11 console.log('Password:', process.env.MESHCENTRAL_PASSWORD ? '***' : 'MISSING');
14 const api = new MeshCentralAPI({
15 url: process.env.MESHCENTRAL_URL,
16 username: process.env.MESHCENTRAL_USERNAME,
17 password: process.env.MESHCENTRAL_PASSWORD
21 console.log('1. Testing login...');
22 const loginSuccess = await api.login();
25 throw new Error('Login failed');
28 console.log('✅ Login successful\n');
30 console.log('2. Fetching meshes (device groups)...');
31 const meshes = await api.getMeshes();
32 console.log(`✅ Found ${meshes.length} mesh(es)`);
33 if (meshes.length > 0) {
34 meshes.forEach(mesh => {
35 console.log(` - ${mesh.name} (${mesh._id})`);
40 console.log('3. Fetching nodes (devices)...');
41 const nodes = await api.getNodes();
42 console.log(`✅ Found ${nodes.length} node(s)`);
43 if (nodes.length > 0) {
44 nodes.forEach(node => {
45 console.log(` - ${node.name} (${node._id})`);
50 console.log('✅ All API tests passed!');
53 console.error('❌ API test failed:', error.message);
54 console.error(error.stack);