EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
test-meshcentral.js
Go to the documentation of this file.
1require('dotenv').config();
2const MeshCentralAPI = require('./lib/meshcentral-api.js');
3
4/**
5 *
6 */
7async function test() {
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');
12 console.log();
13
14 const api = new MeshCentralAPI({
15 url: process.env.MESHCENTRAL_URL,
16 username: process.env.MESHCENTRAL_USERNAME,
17 password: process.env.MESHCENTRAL_PASSWORD
18 });
19
20 try {
21 console.log('1. Testing login...');
22 const loginSuccess = await api.login();
23
24 if (!loginSuccess) {
25 throw new Error('Login failed');
26 }
27
28 console.log('✅ Login successful\n');
29
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})`);
36 });
37 }
38 console.log();
39
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})`);
46 });
47 }
48 console.log();
49
50 console.log('✅ All API tests passed!');
51 process.exit(0);
52 } catch (error) {
53 console.error('❌ API test failed:', error.message);
54 console.error(error.stack);
55 process.exit(1);
56 }
57}
58
59test();