### getAllServers Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves all servers. ```javascript const res = await app.getAllServers() // res = Server[] ``` -------------------------------- ### editUser Examples Source: https://jspteroapi.linux123123.com/classes/index.Application.html Examples showing how to update user information using the editUser method. ```javascript const res = await app.editUser(1, 'linux123123', undefined, 'ADMIN_LAST) // res = UserAttributes ``` ```javascript app.editUser(1, undefined, 'Linux').then((res) => console.log(res)) // res = UserAttributes ``` -------------------------------- ### reinstallServer Examples Source: https://jspteroapi.linux123123.com/classes/index.Client.html Triggers a server reinstallation process. ```javascript const res = await client.reinstallServer('c2f5a3b6') // res = Successfuly started reinstalling! ``` ```javascript client.reinstallServer('c2f5a3b6').then((res) => console.log(res)) // res = Successfuly started reinstalling! ``` -------------------------------- ### listeners method example Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Shows how to use the listeners method to get a copy of the array of listeners for a specific event. The example uses a server connection event and prints the listeners array. ```javascript server.on('connection', (stream) => { console.log('someone connected!'); }); console.log(util.inspect(server.listeners('connection'))); // Prints: [ [Function] ] ``` -------------------------------- ### getAllNodes Examples Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves all nodes. ```javascript const res = await app.getAllNodes() // res = Node[] ``` ```javascript app.getAllNodes().then((res) => console.log(res)) // res = Node[] ``` -------------------------------- ### editServerStartup Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Updates the startup command for a server using editServerStartup. ```javascript app.editServerStartup(1, 'node index.js').then((res) => console.log(res)) // res = ServerAttributes ``` -------------------------------- ### createServer example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Demonstrates creating a new server using the createServer method. ```typescript const res = await app.createServer('BUNGEE', 1, 'BUNGEE SERVER', 1, 1) // res = ServerAttributes ``` -------------------------------- ### getAllLocations Examples Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves all available locations. ```javascript const res = await app.getAllLocations() // res = Location[] ``` ```javascript app.getAllLocations().then((res) => console.log(res)) // res = Location[] ``` -------------------------------- ### restoreBackup Examples Source: https://jspteroapi.linux123123.com/classes/index.Client.html Restores a server from a specific backup ID. ```javascript const res = await client.restoreBackup('7e74354d', '3a4e4b2a') // res = Sucessfully restored backup ``` ```javascript client.restoreBackup('7e74354d', '3a4e4b2a').then((res) => console.log(res)) // res = Sucessfully restored backup ``` -------------------------------- ### getServerInfo Async/Await Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves server information using async/await. ```javascript const res = await app.getServerInfo(1) // res = ServerAttributes ``` -------------------------------- ### on method example: server.on('connection', ...) Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Adds a listener for the 'connection' event. The listener is called every time the event is emitted. The example logs a message when a connection occurs. ```javascript server.on('connection', (stream) => { console.log('someone connected!'); }); ``` -------------------------------- ### getAllNests Examples Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves all nests. ```javascript const res = await app.getAllNests() // res = Nest[] ``` ```javascript app.getAllNests().then((res) => console.log(res)) // res = Nest[] ``` -------------------------------- ### getServerResources Examples Source: https://jspteroapi.linux123123.com/classes/index.Client.html Retrieves server resource usage statistics. ```javascript const res = await client.getServerResources('c2f5a3b6') // res = ServerResources ``` ```javascript client.getServerResources('c2f5a3b6').then((res) => console.log(res)) // res = ServerResources ``` -------------------------------- ### Install JSPteroAPI via Yarn Source: https://jspteroapi.linux123123.com/index.html Command to install the library using the yarn package manager. ```bash yarn add jspteroapi ``` -------------------------------- ### renameServer Examples Source: https://jspteroapi.linux123123.com/classes/index.Client.html Updates the display name of a server. ```javascript const res = await client.renameServer('c2f5a3b6', 'Best Server') // res = Successfuly set new server name! ``` ```javascript client.renameServer('c2f5a3b6', 'Best Server').then((res) => console.log(res)) // res = Successfuly set new server name! ``` -------------------------------- ### createNode async/await example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Demonstrates creating a new node using the async/await syntax. ```typescript const res = await app.createNode('NEW node', 'Good node', 1, 'node.gfd.com', 'https', 8192, 500000) // res = NodeAttributes ``` -------------------------------- ### Install JSPteroAPI via NPM Source: https://jspteroapi.linux123123.com/index.html Command to install the library using the npm package manager. ```bash npm install jspteroapi ``` -------------------------------- ### eventNames method example Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Shows how to use the eventNames method to get an array of event names for which listeners are registered. It includes both string and Symbol event names. ```javascript const EventEmitter = require('events'); const myEE = new EventEmitter(); myEE.on('foo', () => {}); myEE.on('bar', () => {}); const sym = Symbol('symbol'); myEE.on(sym, () => {}); console.log(myEE.eventNames()); // Prints: [ 'foo', 'bar', Symbol(symbol) ] ``` -------------------------------- ### EventEmitter on and prependListener example Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Shows that listeners are invoked in the order they are added, but prependListener adds a listener to the beginning. The example prints 'b' then 'a'. ```javascript const myEE = new EventEmitter(); myEE.on('foo', () => console.log('a')); myEE.prependListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` -------------------------------- ### emit method example Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Shows how to use the emit method with multiple listeners. It demonstrates registering three listeners for the 'event' event and then emitting the event with parameters. The output shows the listeners array and the order of listener execution. ```javascript const EventEmitter = require('events'); const myEmitter = new EventEmitter(); // First listener myEmitter.on('event', function firstListener() { console.log('Helloooo! first listener'); }); // Second listener myEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`); }); // Third listener myEmitter.on('event', function thirdListener(...args) { const parameters = args.join(', '); console.log(`event with parameters ${parameters} in third listener`); }); console.log(myEmitter.listeners('event')); myEmitter.emit('event', 1, 2, 3, 4, 5); // Prints: // [ // [Function: firstListener], // [Function: secondListener], // [Function: thirdListener] // ] // Helloooo! first listener // event with parameters 1, 2 in second listener // event with parameters 1, 2, 3, 4, 5 in third listener ``` -------------------------------- ### getAllUsers Async/Await Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves all users using the async/await syntax. ```javascript const res = await app.getAllUsers() // res = User[] ``` -------------------------------- ### getEggInfo Async/Await Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves information for a specific egg using async/await. ```javascript const res = await app.getEggInfo(1, 1) // res = EggAttributes ``` -------------------------------- ### EventEmitter once and prependOnceListener example Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Shows that prependOnceListener adds a one-time listener to the beginning of the listeners array. The example prints 'b' then 'a'. ```javascript const myEE = new EventEmitter(); myEE.once('foo', () => console.log('a')); myEE.prependOnceListener('foo', () => console.log('b')); myEE.emit('foo'); // Prints: // b // a ``` -------------------------------- ### getAllServers Promise Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves all servers using a promise-based approach. ```javascript app.getAllServers().then((res) => console.log(res)) // res = Server[] ``` -------------------------------- ### getNodeConfig Async/Await Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves node configuration using async/await. ```javascript const res = await app.getNodeConfig(1) // res = NodeConfig ``` -------------------------------- ### getServerInfo Example Source: https://jspteroapi.linux123123.com/classes/index.Client.html Retrieves server information using the server ID. ```javascript client.getServerInfo('c2f5a3b6').then((res) => console.log(res)) // res = ServerAttributes ``` -------------------------------- ### getAllAllocations Examples Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves all allocations for a specific node. ```javascript const res = await app.getAllAllocations(1) // res = NodeAttributes ``` ```javascript app.getAllAllocations(1).then((res) => console.log(res)) // res = NodeAttributes ``` -------------------------------- ### renameFile Examples Source: https://jspteroapi.linux123123.com/classes/index.Client.html Renames files within a server directory. ```javascript const res = await client.renameFile('c2f5a3b6', { root: '/', files: [{ from: 'LICENSE', to: 'LIC' }] }) // res = Successfuly renamed! ``` ```javascript client.renameFile('c2f5a3b6', { root: '/dist', files: [{ from: 'LICENSE', to: 'LIC' }] }).then((res) => console.log(res)) // res = Successfuly renamed! ``` -------------------------------- ### getSubUserInfo Examples Source: https://jspteroapi.linux123123.com/classes/index.Client.html Retrieves information about a specific sub-user on a server. ```javascript const res = await client.getSubUserInfo('c2f5a3b6', '60a7aec3-e17d-4aa9-abb3-56d944d204b4') // res = SubUserAttributes ``` ```javascript client.getSubUserInfo('c2f5a3b6', '60a7aec3-e17d-4aa9-abb3-56d944d204b4').then((res) => console.log(res)) // res = SubUserAttributes ``` -------------------------------- ### Execute API functions with Async/Await Source: https://jspteroapi.linux123123.com/index.html Example of calling an application function using the async/await syntax. ```javascript const res = await application.function(parameters); ``` -------------------------------- ### createNode promise example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Demonstrates creating a new node using the promise .then() syntax. ```typescript app.createNode('NEW node', 'Good node', 1, 'node.gfd.com', 'https', 8192, 500000).then((res) => console.log(res)) // res = NodeAttributes ``` -------------------------------- ### getServerInfo Promise Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves server information using a promise-based approach. ```javascript app.getServerInfo(1).then((res) => console.log(res)) // res = ServerAttributes ``` -------------------------------- ### getNodeInfo Async/Await Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves node information using async/await. ```javascript const res = await app.getNodeInfo(1) // res = NodeAttributes ``` -------------------------------- ### getAllUsers Promise Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves all users using a promise-based approach. ```javascript app.getAllUsers().then((res) => console.log(res)) // res = User[] ``` -------------------------------- ### getEggInfo Promise Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves information for a specific egg using a promise-based approach. ```javascript app.getEggInfo(1, 1).then((res) => console.log(res)) // res = EggAttributes ``` -------------------------------- ### getNestInfo Async/Await Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves nest details using async/await. ```javascript const res = await app.getNestInfo(1) // res = NestAttributes ``` -------------------------------- ### getLocationInfo Async/Await Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves location information using async/await. ```javascript const res = await app.getLocationInfo(1) // res = LocationAttributes ``` -------------------------------- ### getNodeConfig Promise Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves node configuration using a promise-based approach. ```javascript app.getNodeConfig(1).then((res) => console.log(res)) // res = NodeConfig ``` -------------------------------- ### Execute API functions with Promises Source: https://jspteroapi.linux123123.com/index.html Example of calling an application function using the .then() promise syntax. ```javascript application.function(parameters).then((response) => { // response }); ``` -------------------------------- ### Delete Database with app.resetDatabasePassword (Async/Await) Source: https://jspteroapi.linux123123.com/classes/index.Application.html Deletes a database from a server using async/await. Note: The method name in the example is resetDatabasePassword. ```javascript const res = await app.resetDatabasePassword(1, 1) // res = Successfully deleted the database! ``` -------------------------------- ### once method example: server.once('connection', ...) Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Adds a one-time listener for the 'connection' event. The listener is removed and invoked the next time the event is triggered. ```javascript server.once('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` -------------------------------- ### prependListener method example: server.prependListener('connection', ...) Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Adds a listener to the beginning of the listeners array for the 'connection' event. The listener is called every time the event is emitted. ```javascript server.prependListener('connection', (stream) => { console.log('someone connected!'); }); ``` -------------------------------- ### prependOnceListener method example: server.prependOnceListener('connection', ...) Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Adds a one-time listener to the beginning of the listeners array for the 'connection' event. The listener is removed and invoked the next time the event is triggered. ```javascript server.prependOnceListener('connection', (stream) => { console.log('Ah, we have our first user!'); }); ``` -------------------------------- ### Create Database with await Source: https://jspteroapi.linux123123.com/classes/index.Application.html Demonstrates creating a database for a specific server using the await syntax. ```typescript const res = await app.createDatabase('DATABASE_1', 1, 1) // res = DatabaseAttributes ``` -------------------------------- ### constructor Source: https://jspteroapi.linux123123.com/classes/index.Application.html Creates a new Application instance with the panel host and API key. Optionally accepts an error handler and fast login flag. ```APIDOC ## constructor ### Description Creates a new Application instance with the panel host and API key. Optionally accepts an error handler and fast login flag. ### Method constructor ### Parameters - **host** (string) - Required - Panels address - **key** (string) - Required - Api key to use - **errorHandler** ((error: JSPteroAPIError) => void) - Optional - Function to handle errors - **fast** (boolean) - Optional - Fast login (No credential check) ### Returns Application ``` -------------------------------- ### Create Database with Promise Source: https://jspteroapi.linux123123.com/classes/index.Application.html Demonstrates creating a database using the Promise then syntax. ```typescript app.createDatabase('DATABASE_1', 1, 1).then((res) => console.log(res)) // res = DatabaseAttributes ``` -------------------------------- ### Create Server with app.createServer Source: https://jspteroapi.linux123123.com/classes/index.Application.html Creates a new server instance using the specified parameters and returns a Promise resolving to ServerAttributes. ```javascript app.createServer('BUNGEE', 1, 'BUNGEE SERVER', 1, 1).then((res) => console.log(res)) // res = ServerAttributes ``` -------------------------------- ### Create Backup with async/await Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a server backup using async/await. ```javascript const res = await client.createBackup('7e74354d') // res = BackupAttributes ``` -------------------------------- ### startConsoleConnection async usage Source: https://jspteroapi.linux123123.com/classes/index.Client.html Establishes a websocket console connection using async/await. ```javascript const res = await client.startConsoleConnection('c2f5a3b6') // res = WebsocketClient ``` -------------------------------- ### setPowerState(serverId: string, action: "stop" | "start" | "restart" | "kill"): Promise Source: https://jspteroapi.linux123123.com/classes/index.Client.html Sets the power state of a server to start, stop, restart, or kill. Returns a success message. ```APIDOC ## setPowerState ### Description Sets the power state of a server to start, stop, restart, or kill. Returns a success message. ### Method setPowerState ### Signature (serverId: string, action: "stop" | "start" | "restart" | "kill") => Promise ### Parameters - **serverId** (string) - Required - ID of the server to send a command to - **action** ("stop" | "start" | "restart" | "kill") - Required - start / stop / restart / kill ### Returns Promise - If successful returns Successfuly set power state! ### Example ``` const res = await client.setPowerState('c2f5a3b6', 'start') // res = Successfuly set power state! ``` ### Example ``` client.setPowerState('c2f5a3b6', 'kill).then((res) => console.log(res)) // res = Successfuly set power state! ``` ``` -------------------------------- ### Create Database with async/await Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a new database for a server using async/await. ```javascript const res = await client.createDatabase('c2f5a3b6', 'Information') // res = DatabaseAttributes ``` -------------------------------- ### createServer Source: https://jspteroapi.linux123123.com/classes/index.Application.html Creates a new server with the specified configuration and returns the server attributes. ```APIDOC ## createServer ### Description Creates a new server with the specified configuration and returns the server attributes. ### Method createServer ### Signature createServer(name: string, ownerId: number, description: string, nestId: number, eggId: number, defaultAllocationId: number, addAllocationIds?: number[], environment?: ServerEnvironment, cpu?: number, ram?: number, disk?: number, amountOfDatabases?: number, amountOfAllocations?: number, amountOfBackups?: number, startupCmd?: string, dockerImage?: string, swap?: number, io?: number, startOnCompletion?: boolean, options?: ServerIncludesInput): Promise ### Parameters - **name** (string) - Required - The name of the server - **ownerId** (number) - Required - The ID of the owner of the server - **description** (string) - Required - A description for the server - **nestId** (number) - Required - The ID of the nest - **eggId** (number) - Required - The ID of the egg - **defaultAllocationId** (number) - Required - The ID of the default allocation - **addAllocationIds** (number[]) - Optional - Additional allocation IDs - **environment** (ServerEnvironment) - Optional - Environment variables for the server - **cpu** (number) - Optional - CPU limit - **ram** (number) - Optional - RAM limit - **disk** (number) - Optional - Disk limit - **amountOfDatabases** (number) - Optional - Number of databases - **amountOfAllocations** (number) - Optional - Number of allocations - **amountOfBackups** (number) - Optional - Number of backups - **startupCmd** (string) - Optional - Startup command - **dockerImage** (string) - Optional - Docker image - **swap** (number) - Optional - Swap limit - **io** (number) - Optional - I/O ratio - **startOnCompletion** (boolean) - Optional - Whether to start the server on completion - **options** (ServerIncludesInput) - Optional - Include information about relationships ### Returns Promise - Returns the created server object ### Example ``` const res = await app.createServer('BUNGEE', 1, 'BUNGEE SERVER', 1, 1) // res = ServerAttributes ``` ``` -------------------------------- ### getAllNestEggs Examples Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves all eggs associated with a specific nest. ```javascript const res = await app.getAllNestEggs(1) // res = Egg[] ``` ```javascript app.getAllNestEggs(1).then((res) => console.log(res)) // res = Egg[] ``` -------------------------------- ### Create User with app.createUser (Async/Await) Source: https://jspteroapi.linux123123.com/classes/index.Application.html Creates a new user using async/await syntax. Returns a Promise resolving to UserAttributes. ```javascript const res = await app.createUser('linux123123', 'Linus', 'ADMIN', 'api@gmail.com') // res = UserAttributes ``` -------------------------------- ### Initialize JSPteroAPI Client Source: https://jspteroapi.linux123123.com/index.html Import the library and initialize the Application and Client API instances with your host and token. ```javascript const node = require('jspteroapi'); const application = new node.Application('HOST', 'TOKEN'); // for application API const client = new node.Client('HOST', 'TOKEN'); // for Client API ``` -------------------------------- ### createServer Source: https://jspteroapi.linux123123.com/classes/index.Application.html Creates a new server with the specified configuration. Returns a Promise resolving to ServerAttributes. ```APIDOC ## createServer ### Description Creates a new server with the specified configuration. ### Method createServer ### Signature createServer(name: string, ownerId: number, description: string, nestId: number, eggId: number, defaultAllocationId: number, addAllocationIds?: number[], environment?: ServerEnvironment, cpu?: number, ram?: number, disk?: number, amountOfDatabases?: number, amountOfAllocations?: number, amountOfBackups?: number, startupCmd?: string, dockerImage?: string, swap?: number, io?: number, startOnCompletion?: boolean, options?: ServerIncludesInput): Promise ### Parameters - **name** (string) - Required - Name of server to create - **ownerId** (number) - Required - User ID of who should own this server - **description** (string) - Required - Description of server - **nestId** (number) - Required - ID of the nest to use when making a server - **eggId** (number) - Required - Egg ID to use when installing the server - **defaultAllocationId** (number) - Required - Default allocation ID - **addAllocationIds** (number[]) - Optional - Additional allocation IDs (default []) - **environment** (ServerEnvironment) - Optional - Server environment variables. Some are REQUIRED! If there is a default value and none is provided default is used! - **cpu** (number) - Optional - Amount of cpu resources to give (1 core = 100) (0 unlimited) (default 0) - **ram** (number) - Optional - Amount of memory resources to give (1024 = 1GB) (0 unlimited) (default 0) - **disk** (number) - Optional - Amount of disk space to give (1024 = 1GB) (0 unlimited) (default 0) - **amountOfDatabases** (number) - Optional - The max amount of databases a server can use (default 0) - **amountOfAllocations** (number) - Optional - The max amount of allocation(s) a server can use (default 0) - **amountOfBackups** (number) - Optional - The max amount of backups a server can use (default 0) - **startupCmd** (string) - Optional - The command to use when starting this server - **dockerImage** (string) - Optional - The image to use from Docker - **swap** (number) - Optional - The amount of Swap the server has (default 0) - **io** (number) - Optional - Set this to 500 (default 500) - **startOnCompletion** (boolean) - Optional - Start on completion (default false) - **options** (ServerIncludesInput) - Optional - Include information about server relationships ### Returns Promise ### Example ``` app.createServer('BUNGEE', 1, 'BUNGEE SERVER', 1, 1).then((res) => console.log(res)) // res = ServerAttributes ``` ``` -------------------------------- ### Create Backup with Promise Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a server backup using a Promise. ```javascript client.createBackup('7e74354d', 'RandomBackup').then((res) => console.log(res)) // res = BackupAttributes ``` -------------------------------- ### Create Location with await Source: https://jspteroapi.linux123123.com/classes/index.Application.html Demonstrates creating a new location using the await syntax. ```typescript const res = await app.createLocation('Home') // res = LocationAttributes ``` -------------------------------- ### getNodeInfo Promise Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves node information using a promise-based approach. ```javascript app.getNodeInfo(1).then((res) => console.log(res)) // res = NodeAttributes ``` -------------------------------- ### connect Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Establishes the WebSocket connection. ```APIDOC ## connect ### Description Establishes the WebSocket connection. ### Method connect ### Parameters None ### Returns void ``` -------------------------------- ### getNestInfo Promise Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves nest details using a promise-based approach. ```javascript app.getNestInfo(1).then((res) => console.log(res)) // res = NestAttributes ``` -------------------------------- ### getLocationInfo Promise Example Source: https://jspteroapi.linux123123.com/classes/index.Application.html Retrieves location information using a promise-based approach. ```javascript app.getLocationInfo(1).then((res) => console.log(res)) // res = LocationAttributes ``` -------------------------------- ### new Client(host, key, errorHandler?, fast?) Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a new Client instance for interacting with the Pterodactyl panel API. Requires the panel address and API key, with optional custom error handler and fast login flag. ```APIDOC ## new Client(host, key, errorHandler?, fast?) ### Description Creates a new Client instance for the JSPteroAPI library. ### Constructor new Client(host: string, key: string, errorHandler?: ((error: JSPteroAPIError) => void), fast?: boolean): Client ### Parameters - **host** (string) - Required - Panels address - **key** (string) - Required - Api key to use - **errorHandler** (function) - Optional - A custom function to handle errors. Signature: (error: JSPteroAPIError) => void - **fast** (boolean) - Optional - Fast login (No credential check). Default: false ### Returns Client ``` -------------------------------- ### Create Allocation with await Source: https://jspteroapi.linux123123.com/classes/index.Application.html Demonstrates creating an allocation on a specific node using the await syntax. ```typescript const res = await app.createAllocation(1, ['25565']) // res = Successfully created! ``` -------------------------------- ### Create Database with Promise Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a new database for a server using a Promise. ```javascript client.createDatabase('c2f5a3b6', 'info').then((res) => console.log(res)) // res = DatabaseAttributes ``` -------------------------------- ### startConsoleConnection promise usage Source: https://jspteroapi.linux123123.com/classes/index.Client.html Establishes a websocket console connection using promise chaining. ```javascript client.startConsoleConnection('c2f5a3b6').then((res) => console.log(res)) // res = WebsocketClient ``` -------------------------------- ### reinstallServer Source: https://jspteroapi.linux123123.com/classes/index.Client.html Reinstalls a server. ```APIDOC ## reinstallServer ### Description Reinstalls a server. ### Method SDK Method ### Signature client.reinstallServer(serverId: string): Promise ### Parameters - **serverId** (string) - Required - ID of the server to get (In the settings tab of server/in link) ### Returns Promise - Successfuly started reinstalling! ### Example ```js const res = await client.reinstallServer('c2f5a3b6') // res = Successfuly started reinstalling! ``` ``` -------------------------------- ### Get event listeners with getEventListeners Source: https://jspteroapi.linux123123.com/classes/client_Websocket.WebsocketClient.html Retrieves a copy of the array of listeners for a specific event name from an EventEmitter or EventTarget. ```javascript const { getEventListeners, EventEmitter } = require('events'); { const ee = new EventEmitter(); const listener = () => console.log('Events are fun'); ee.on('foo', listener); getEventListeners(ee, 'foo'); // [listener] } { const et = new EventTarget(); const listener = () => console.log('Events are fun'); et.addEventListener('foo', listener); getEventListeners(et, 'foo'); // [listener] } ``` -------------------------------- ### ServerFileCreateFolder Interface Source: https://jspteroapi.linux123123.com/interfaces/client_interfaces_ServerFile.ServerFileCreateFolder.html Defines the structure for creating a folder, including the folder name and root path. ```APIDOC ## ServerFileCreateFolder Interface ### Description Defines the structure for creating a folder, including the folder name and root path. ### Properties - **name** (string) - The name of the folder to create. - **root** (string) - The root path where the folder should be created. ``` -------------------------------- ### getAccount2FADetails(): Promise Source: https://jspteroapi.linux123123.com/classes/index.Client.html Retrieves the TOTP QR code image URL (otpauth) for the account's 2FA setup. ```APIDOC ## getAccount2FADetails(): Promise ### Description Retrieves the TOTP QR code image URL (otpauth) for the account's 2FA setup. ### Method SDK Method ### Returns Promise - TOTP QR code image url (otpauth) ### Example ```js const res = await client.getAccountInfo() // res = string (otpauth) ``` ``` -------------------------------- ### createBackup(serverId: string, name?: string, ignored?: string[], isLocked?: boolean): Promise Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a backup for a server with optional name, ignored files, and lock status. ```APIDOC ## createBackup(serverId: string, name?: string, ignored?: string[], isLocked?: boolean): Promise ### Description Creates a backup for a server with optional name, ignored files, and lock status. ### Method createBackup ### Parameters - **serverId** (string) - Required - ID of the server to get (In the settings tab of server/in link) - **name** (string) - Optional - Name of the backup (default '') - **ignored** (string[]) - Optional - Ignored files / folders (default []) - **isLocked** (boolean) - Optional - (default false) ### Returns Promise ### Example ``` const res = await client.createBackup('7e74354d') // res = BackupAttributes ``` ### Example ``` client.createBackup('7e74354d', 'RandomBackup').then((res) => console.log(res)) // res = BackupAttributes ``` ``` -------------------------------- ### Delete Database with app.resetDatabasePassword (Promise) Source: https://jspteroapi.linux123123.com/classes/index.Application.html Deletes a database from a server using Promise chaining. Note: The method name in the example is resetDatabasePassword. ```javascript app.resetDatabasePassword(1, 2).then((res) => console.log(res)) // res = Successfully deleted the database! ``` -------------------------------- ### Create User with app.createUser (Promise) Source: https://jspteroapi.linux123123.com/classes/index.Application.html Creates a new user using Promise chaining. Returns a Promise resolving to UserAttributes. ```javascript app.createUser('linux123123', 'Linus', 'ADMIN', 'api@gmail.com').then((res) => console.log(res)) // res = UserAttributes ``` -------------------------------- ### editServerStartup usage Source: https://jspteroapi.linux123123.com/classes/index.Application.html Updates the server startup command. ```typescript const res = await app.editServerStartup(1, 'node index.js') // res = ServerAttributes ``` -------------------------------- ### createFolder Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a new folder on the server. Returns a promise that resolves to a success message string. ```APIDOC ## createFolder ### Description Creates a new folder on the server. ### Method createFolder ### Signature createFolder(serverId: string, data: ServerFileCreateFolder): Promise ### Parameters - **serverId** (string) - Required - ID of the server to get (In the settings tab of server/in link) - **data** (ServerFileCreateFolder) - Required - An object composed of root of the file and file to remove ### Returns Promise ### Example ``` const res = await client.createFolder('c2f5a3b6', { root: '/', name: 'world' }) // res = Successfuly created! ``` ``` -------------------------------- ### createFolder(serverId: string, data: ServerFileCreateFolder): Promise Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a folder on a server. Returns a success message if successful. ```APIDOC ## createFolder(serverId: string, data: ServerFileCreateFolder): Promise ### Description Creates a folder on a server. Returns a success message if successful. ### Method createFolder ### Parameters - **serverId** (string) - Required - ID of the server to get (In the settings tab of server/in link) - **data** (ServerFileCreateFolder) - Required - Data for creating a folder ### Returns Promise ### Example ``` const res = await client.createFolder('c2f5a3b6', { root: '/', name: 'newFolder' }) // res = Successfuly created! ``` ``` -------------------------------- ### editServerStartup(serverId: number, options: EditServerStartup): Promise Source: https://jspteroapi.linux123123.com/classes/index.Application.html Edits the startup configuration of a server. Takes the server ID and an EditServerStartup options object, and returns a Promise resolving to ServerAttributes. ```APIDOC ## editServerStartup(serverId: number, options: EditServerStartup): Promise ### Description Edits the startup configuration of a server. ### Method SDK Method ### Parameters - **serverId** (number) - Required - The external server ID to get the details of. - **options** (EditServerStartup) - Required - Include information about server relationships. ### Returns Promise ### Example ```js app.editServerStartup(1, 'node index.js').then((res) => console.log(res)) // res = ServerAttributes ``` ``` -------------------------------- ### Create Location with Promise Source: https://jspteroapi.linux123123.com/classes/index.Application.html Demonstrates creating a new location using the Promise then syntax. ```typescript app.createLocation('Home').then((res) => console.log(res)) // res = LocationAttributes ``` -------------------------------- ### Create Allocation with Promise Source: https://jspteroapi.linux123123.com/classes/index.Application.html Demonstrates creating an allocation with an alias using the Promise then syntax. ```typescript app.createAllocation(1, ['25565'], 'minecraft').then((res) => console.log(res)) // res = Successfully created! ``` -------------------------------- ### Create API Key with async/await Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a new API key using async/await. ```javascript const res = await client.createApiKey('TESTING', []) // res = ApiKey + meta (token) ``` -------------------------------- ### createFolder usage Source: https://jspteroapi.linux123123.com/classes/index.Client.html Creates a new folder on the specified server using the provided root path and folder name. ```javascript const res = await client.createFolder('c2f5a3b6', { root: '/', name: 'world' }) // res = Successfuly created! ``` ```javascript client.createFolder('c2f5a3b6', { root: '/', name: 'world' }).then((res) => console.log(res)) // res = Successfuly created! ``` -------------------------------- ### startConsoleConnection(serverId: string): Promise Source: https://jspteroapi.linux123123.com/classes/index.Client.html Connects to the server websocket with automatic authentication. Exposes the websocket client. ```APIDOC ## startConsoleConnection ### Description Connects to the server websocket with automatic authentication. Exposes the websocket client. ### Method startConsoleConnection ### Signature (serverId: string) => Promise ### Parameters - **serverId** (string) - Required - ID of the server to get (In the settings tab of server/in link) ### Returns Promise - WebsocketClient ### Remarks This method is used to connect to server websocket and have automatic authentication. This exposes the websocket client. ### Example ``` const res = await client.startConsoleConnection('c2f5a3b6') // res = WebsocketClient ``` ### Example ``` client.startConsoleConnection('c2f5a3b6').then((res) => console.log(res)) // res = WebsocketClient ``` ``` -------------------------------- ### editServerStartup(serverId: number, options: EditServerStartup): Promise Source: https://jspteroapi.linux123123.com/classes/index.Application.html Edits a server's startup configuration by server ID with the provided options. Returns the updated server information. ```APIDOC ## editServerStartup(serverId: number, options: EditServerStartup): Promise ### Description Edits a server's startup configuration by server ID with the provided options. Returns the updated server information. ### Method SDK Method ### Signature `editServerStartup(serverId: number, options: EditServerStartup): Promise` ### Parameters - **serverId** (number) - Required - The server ID to get the details of. - **options** (EditServerStartup) - Required - The options to edit ### Returns Promise - Server information ### Example ```js const res = await app.editServerStartup(1, 'node index.js') // res = ServerAttributes ``` ```