Proxmox API Data Encoding Format

ltcptgeneral

Member
Jun 21, 2022
13
0
6
I am trying to send a PUT request to `/nodes/{node}/qemu/{vmid}/resize` with the following data:
`disk=sata3&size=+1G`
However, no matter how I encode this data, I keep getting the error:
`size: "value does not match the regex pattern"`
I have tied URL encoding, json, plaintext, etc. I am using nodejs https module.

There are no issues when sending the data: `delete=sata3` to `/nodes/{node}/qemu/{vmid}/config`.

What exactly is the required format for the API?
 
it would help if you showed your exact command line.
This works just fine for me:
Code:
curl --verbose --insecure  --cookie "$(<cookie)" --header "$(<csrftoken)" -X PUT --data-urlencode disk="scsi1" --data-urlencode size="+1G"  https://127.0.0.1:8006/api2/json/nodes/pve7demo1/qemu/100/resize

https://pve.proxmox.com/wiki/Proxmox_VE_API
https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}/resize


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
it would help if you showed your exact command line.
This works just fine for me:
Code:
curl --verbose --insecure  --cookie "$(<cookie)" --header "$(<csrftoken)" -X PUT --data-urlencode disk="scsi1" --data-urlencode size="+1G"  https://127.0.0.1:8006/api2/json/nodes/pve7demo1/qemu/100/resize

https://pve.proxmox.com/wiki/Proxmox_VE_API
https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}/resize


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
Curl works just fine for me too. I am having issue with nodejs https module. Here's the relevant code:

Code:
body = "delete=sata3&size=+1G";
        if (body) {
            request.write(encodeURIComponent(body));
        }
...

To the best of my understanding, this should encode the information the same way as curl.
 
Last edited:
my guess is your code encodes the '+', which doesn't happen for regular url encoding (just the component variant).
 
my guess is your code encodes the '+', which doesn't happen for regular url encoding (just the component variant).
Ok so your suggested fix works, but I'm not exactly sure why it works:

Like you suggest, instead of encoding a search query string and using encodeURI, encoding a JS object using SearchParams works:
Code:
body = {
    delete: "sata3",
    size: "+1G"
}
if (body) {
    request.write(new URLSearchParams(body).toString());
}

This works just fine. What's weird is that comparing the two output strings claims they are exactly the same.
 
Last edited:
what I meant is the following difference:

Code:
> encodeURI("delete=sata3&size=+1G");
'delete=sata3&size=+1G'
> encodeURIComponent("delete=sata3&size=+1G");
'delete%3Dsata3%26size%3D%2B1G'

but upon closer inspection, what curl actually sends as body (with Content-Type "application/x-www-form-urlencoded") is

Code:
disk=scsi1&size=%2B1G

(note that this is a PUT request, so we are not talking about data being transferred via the URL)