Proxmox API Client

1.1.1 · active · verified Tue Apr 21

proxmox-api is a comprehensive JavaScript and TypeScript client library for interacting with the Proxmox VE API. Currently stable at version `1.1.1`, it offers a unique mapping approach where Proxmox API paths are directly translated into chained method calls (e.g., `/nodes/mynode` becomes `proxmox.nodes.mynode`). The library's core differentiator is its 100% mapping of available Proxmox API calls, complete with extensive TypeScript typings that enable rich IntelliSense, significantly reducing the need to consult external API documentation. It features a small footprint, weighing less than 10KB including its integrated documentation. Releases appear to be ad-hoc but frequent, driven by bug fixes and compatibility updates, such as recent enhancements for ESM and Proxmox 8 support. It supports multiple authentication methods including username/password and API tokens.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Proxmox API client, connect to a Proxmox host (using environment variables for sensitive data), list all cluster nodes, and then iterate through each node to retrieve and log configuration details for all running QEMU virtual machines.

import proxmoxApi from "proxmox-api";

// Authorize self-signed certificates if you are not using a valid SSL certificate.
// In a production environment, prefer proper certificate validation or CA setup.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = process.env.PROXMOX_TLS_REJECT_UNAUTHORIZED || "0";

async function test() {
    // Connect to Proxmox using environment variables for credentials.
    // Replace with your actual Proxmox host, username, and password or API token details.
    const proxmox = proxmoxApi({
        host: process.env.PROXMOX_HOST ?? '127.0.0.1',
        password: process.env.PROXMOX_PASSWORD ?? 'your-proxmox-password',
        username: process.env.PROXMOX_USERNAME ?? 'root@pam'
    });

    try {
        // List all nodes in the Proxmox cluster
        const nodes = await proxmox.nodes.$get();
        console.log("Proxmox Nodes:", nodes.map((n: any) => n.node).join(', '));

        // Iterate through each node to list its QEMU VMs
        for (const node of nodes) {
            const theNode = proxmox.nodes.$(node.node);
            console.log(`\n--- VMs on Node: ${node.node} ---`);

            // List Qemu VMs on the current node with full details
            const qemus = await theNode.qemu.$get({ full: true });

            if (qemus.length === 0) {
                console.log(`  No QEMU VMs found on node ${node.node}.`);
                continue;
            }

            // Iterate through Qemu VMs to get their configuration
            for (const qemu of qemus) {
                const config = await theNode.qemu.$(qemu.vmid).config.$get();
                console.log(`  VM Name: ${config.name}, VMID: ${qemu.vmid}, Memory: ${config.memory}MB, Cores: ${config.cores}`);
            }
        }
    } catch (error) {
        console.error("An error occurred:", error);
    }
}

test().catch(console.error);

view raw JSON →