Client Class
The Client class provides an interface for interacting with the Pterodactyl Client API. It supports account management, server control, file operations, backups, networking, schedules, settings, startup variables, and more.
Written By Cptcr
Last updated 12 months ago
Class: Client
Constructor
constructor(apiKey: string) apiKey: The API key used for authentication.
panel: The panel URL fetched from the
Setupclass.
API Endpoints
Account Management
getDetails(): Retrieves account details.
enable2FA(codes: string[]): Enables two-factor authentication.
disable2FA(tokens: string[]): Disables two-factor authentication.
updateEmail(email: string, password: string): Updates the account email.
updatePassword(current_password: string, new_password: string): Updates the account password.
createApiKey(description: string, allowed_ips: string[]): Creates an API key.
deleteApiKey(key_id: string): Deletes an API key.
listApiKeys(): Lists API keys associated with the account.
Example Usage:
const account = await client.account.getDetails(); await client.account.updateEmail("new@example.com", "currentPassword"); await client.account.createApiKey("My Key", ["192.168.1.1"]); Server Management
list(): Retrieves a list of all servers.
showPermissions(server_id): Displays server permissions.
sendCommand(server_id, commandStr): Sends a command to a server.
powerAction(server_id, signal): Sends a power action (start, stop, restart, kill) to a server.
getConsoleDetails(server_id): Retrieves console details.
getResources(server_id): Fetches server resource usage.
getDetails(server_id): Retrieves server details.
Example Usage:
const servers = await client.servers.list(); await client.servers.powerAction("5", "restart"); Backup Management
list(server_id): Lists all backups for a server.
getDetails(server_id, backup_id): Fetches backup details.
create(server_id, backup_data): Creates a backup.
delete(server_id, backup_id): Deletes a backup.
download(server_id, backup_id): Downloads a backup.
Example Usage:
const backups = await client.backups.list("5"); await client.backups.create("5", { name: "DailyBackup" }); File Management
list(server_id, directory?): Lists files in a directory.
getContent(server_id, file_path): Retrieves file content.
download(server_id, file_path): Downloads a file.
rename(server_id, from, to): Renames a file.
copy(server_id, file_path): Copies a file.
write(server_id, file_path, content): Writes content to a file.
compress(server_id, files): Compresses files.
decompress(server_id, file_path): Decompresses a file.
delete(server_id, files): Deletes files.
createFolder(server_id, folder_path): Creates a folder.
upload(server_id, file_data): Uploads a file.
Example Usage:
await client.files.upload("5", formData); await client.files.rename("5", "old.txt", "new.txt"); Network Management
listAllocations(server_id): Lists server allocations.
assignAllocations(server_id, allocation_id): Assigns an allocation.
setAllocationNote(server_id, allocation_id, note): Sets a note on an allocation.
setPrimaryAllocation(server_id, allocation_id): Sets an allocation as primary.
unassignAllocation(server_id, allocation_id): Unassigns an allocation.
Example Usage:
await client.network.setPrimaryAllocation("5", "10"); Conclusion
This documentation provides a full reference for the Client class, which interacts with the Pterodactyl API for managing accounts, servers, backups, networking, schedules, settings, startup variables, users, and file operations. Each endpoint is structured for easy integration within any JavaScript or TypeScript project.