How to create a VM with proxmox API ?

HixS

New Member
Mar 28, 2024
1
0
1
Is anyone familiar with Proxmox API? Specificly on how to create VM, as part of my bootcamp I'm trying to develop a friendly UI (https://github.com/sbendarsky/Proxify.git) using next.js for proxmox and I cannot find a solution on how to do that.
I tried to search the web on how to do that but didn't find anything, I've only found solution on start/stop a VM but not on how to create one.

import axios from 'axios';
import https from 'https';
import { serverRuntimeConfig } from 'next.config';

const proxmox_url = serverRuntimeConfig.proxmoxURL;
const proxmox_token_id = serverRuntimeConfig.proxmox_token_id;
const proxmox_secret = serverRuntimeConfig.proxmox_secret;

const client = axios.create({
baseURL: `${proxmox_url}/api2/json`,
headers: {
Authorization: `PVEAPIToken=${proxmox_token_id}@pam=${proxmox_secret}`,
},
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
});

export default async (req, res) => {
try {
const node = 'proxmox24';
const vmid = '101';
const vmConfig = {
vmid,
ostype: 'l26',
disk: '10',
cores: '2',
memory: '2048',
storage: 'local',
net0: 'virtio,bridge=vmbr159',
ide2: 'local:iso/Fedora-Workstation-Live-x86_64-39-1.5.iso', // Specify the ISO image correctly
};

const response = await client.post(`/nodes/${node}/qemu/`, vmConfig);

if (response.status === 200) {
res.json({ message: 'VM created successfully' });
} else {
res.json({ message: 'Failed to create VM' });
}
} catch (error) {
console.error(error);
res.json({ message: 'An error occurred' });
}
};
 
Last edited:
The API is well described here:
https://pve.proxmox.com/pve-docs/api-viewer/

A VM create in particular is here under POST tab:
https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu

How you can implement it in your framework is really up to you to figure out. You can always test your request with "pvesh" or "curl".
Why not add a "printf" to output your request and see if you constructed it properly. You can also examine API requests in your browser Debug Tools when using PVE GUI.

Good luck



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox