VM Create/Edit/Delete with API

wolfgang

Proxmox Staff Member
Staff member
Oct 1, 2014
4,763
316
83
Hi,
Yes it is.
Post on path /nodes/<Nodename>/qemu
 

Editor

Member
Apr 26, 2017
83
1
8
Turkey
Thank you for your answer.
How do I send specific values via API?
For example;

PHP:
$url = 'https://101.101.101.101:8006/api2/json/nodes/<NODE>/qemu/';
$fields = array(
   'vmid' => urlencode($_POST['vmid']),
   'cores' => urlencode($_POST['cores']),
   'sockets' => urlencode($_POST['sockets']),
   'name' => urlencode($_POST['name']),
   'memory' => urlencode($_POST['memory']),
   'onboot' => urlencode($_POST['onboot'])
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
Could it be a correct CURL?
 

udo

Well-Known Member
Apr 22, 2009
5,855
159
63
Ahrensburg; Germany
Thank you for your answer, really
I understand. Could you tell me that? Can I create or clone VM with API?
Hi,
found your post during an search.

So you can create an vm with pvesh (you must adapt that for php):
Code:
pvesh create /nodes/pve01/qemu -name special-vm -vmid 123 \
             -scsi0 local-lvm:32 \
             -memory 4096 -cpu host -socket 2 -cores 2 \
             -net0 virtio,bridge=vmbr0 \
             -cdrom backup:iso/debian9.iso
Udo
 

Editor

Member
Apr 26, 2017
83
1
8
Turkey
Hi,
found your post during an search.

So you can create an vm with pvesh (you must adapt that for php):
Code:
pvesh create /nodes/pve01/qemu -name special-vm -vmid 123 \
             -scsi0 local-lvm:32 \
             -memory 4096 -cpu host -socket 2 -cores 2 \
             -net0 virtio,bridge=vmbr0 \
             -cdrom backup:iso/debian9.iso
Udo
Thank you Udo!
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE and Proxmox Mail Gateway. We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!