How can we create vm using curl?

There is a full api viewer at <your instance>/pve-docs/api-viewer/index.html.
Under nodes > {node} > qemu you can find the endpoint and options for creating a new vm
 
Yes, it's the same. You only need to create the disk first and create the VM with the previously created VM.
you can also do it in one go - either importing some template disk or creating a new blank one, e.g. for scsi disks:

scsi[n]string [file=]<volume> [,aio=<native|threads|io_uring>] [,backup=<1|0>] [,bps=<bps>] [,bps_max_length=<seconds>] [,bps_rd=<bps>] [,bps_rd_max_length=<seconds>] [,bps_wr=<bps>] [,bps_wr_max_length=<seconds>] [,cache=<enum>] [,cyls=<integer>] [,detect_zeroes=<1|0>] [,discard=<ignore|on>] [,format=<enum>] [,heads=<integer>] [,import-from=<source volume>] [,iops=<iops>] [,iops_max=<iops>] [,iops_max_length=<seconds>] [,iops_rd=<iops>] [,iops_rd_max=<iops>] [,iops_rd_max_length=<seconds>] [,iops_wr=<iops>] [,iops_wr_max=<iops>] [,iops_wr_max_length=<seconds>] [,iothread=<1|0>] [,mbps=<mbps>] [,mbps_max=<mbps>] [,mbps_rd=<mbps>] [,mbps_rd_max=<mbps>] [,mbps_wr=<mbps>] [,mbps_wr_max=<mbps>] [,media=<cdrom|disk>] [,queues=<integer>] [,replicate=<1|0>] [,rerror=<ignore|report|stop>] [,ro=<1|0>] [,scsiblock=<1|0>] [,secs=<integer>] [,serial=<serial>] [,shared=<1|0>] [,size=<DiskSize>] [,snapshot=<1|0>] [,ssd=<1|0>] [,trans=<none|lba|auto>] [,werror=<enum>] [,wwn=<wwn>]Use volume as SCSI hard disk or CD-ROM (n is 0 to 30). Use the special syntax STORAGE_ID:SIZE_IN_GiB to allocate a new volume. Use STORAGE_ID:0 and the 'import-from' parameter to import from an existing volume.
 
I had used this
```
curl --silent --insecure --cookie "$(<cookie)" --header "$(<csrftoken)" -X POST \
-d '{
"name": "my-vm",
"vmid": 121,
"ostype": "l26",
"ide2": "local:iso/CentOS-Stream-8-x86_64-latest-boot.iso,media=cdrom",
"virtio0": "local:local:101/vm-101-disk-1,cache=writeback",
"sockets": 1,
"cores": 2,
"memory": 2048,
"net0": "virtio,bridge=vmbr0"
}' \
https://<hostname>:8006/api2/json/nodes/proxmox2/qemu
```
I am getting this error
"vmid": "property is missing and it is not optional",
 
the VMID is a path parameter that goes into the URL in this case, not into the body.

note that you can just copy a valid curl command line from your browser's dev console for any request the UI does ;)

edit: removed wrong advice - @Folke Gleumes below has the correct hint!
 
Last edited:
The request is missing the mimetype.
Add -H "Content-Type: application/json" to your curl options
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, 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 yours easily in our online shop.

Buy now!