Does pvesh set and create support JSON

rootnetworks

New Member
Feb 13, 2022
24
0
1
31
Hello,

I know pvesh create can use parameter
Code:
pvesh create /nodes/{node}/lxc -vmid 100 -hostname test -storage local \

                                  -password supersecret \

                                  -ostemplate local:vztmpl/debian-9.0-standard_9.5-1_amd64.tar.gz \

                                  -memory 512 -swap 512

How to use create with json data is it possible?

For example:
Code:
pvesh create /nodes/{node}/lxc -json '{ "vmid": 123, "hostname": "test", "storage": "local", "password": "test", "ostemplate": "local:vztmpl/debian-9.0-standard_9.5-1_amd64.tar.gz", "memory":512, "swap": 512 }'

It's a good idea to use pvesh get --output-format=json and then make a quick edit json data then use pvesh set to change config.
 
Last edited:
There are many tools that can format output as Json, but far fewer take json input. As I understand it now, pvesh is a convenient but not the best method of interacting with API. If you want to submit json, there is very little need for an extra layer of pvesh - just use curl or other API capable methods in your favorite language.
One of the faults of the pvesh is that it sends a complex task to be executed, ie VM creation, but has no ability to check if that task was successful. You need to find the task ID and check its status.


Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
There are many tools that can format output as Json, but far fewer take json input. As I understand it now, pvesh is a convenient but not the best method of interacting with API. If you want to submit json, there is very little need for an extra layer of pvesh - just use curl or other API capable methods in your favorite language.
One of the faults of the pvesh is that it sends a complex task to be executed, ie VM creation, but has no ability to check if that task was successful. You need to find the task ID and check its status.


Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
Ya I have make a python script to convert it. Haven't tried the PVE Rest API yet May require API authorization.
 
yeah, the API requires authorization
- either login with user+password to obtain a ticket (valid for ~2h, can be used to get a new one within the validity period, this is what the web GUI uses)
- use an API token (no need to login/refresh, can have less privileges than the associated user, can be revoked independently of the owning user)
- if your API client is running as root on the PVE host (might not be the best idea ;)), you can use pveum ticket to generate tickets (same constraints as using the regular login flow apply)

I'd recommend using an API token. https://pve.proxmox.com/wiki/Proxmox_VE_API contains some more info/pointers/..
 
yeah, the API requires authorization
- either login with user+password to obtain a ticket (valid for ~2h, can be used to get a new one within the validity period, this is what the web GUI uses)
- use an API token (no need to login/refresh, can have less privileges than the associated user, can be revoked independently of the owning user)
- if your API client is running as root on the PVE host (might not be the best idea ;)), you can use pveum ticket to generate tickets (same constraints as using the regular login flow apply)

I'd recommend using an API token. https://pve.proxmox.com/wiki/Proxmox_VE_API contains some more info/pointers/..
I will try it in the future
 

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!