create lxc container via curl + api = bad request (400)

dipe

Active Member
Mar 21, 2013
39
0
26
I am trying to create an lxc container via curl on proxmox 4.2 but am getting error 400, I am setting the required vmid' vm id & 'ostemplate' but i am getting 'property is missing' .... errors . what am I doing wrong?

curl -k -b "PVEAuthCookie=PVE:root@pam:57318DC2::mPRd4bxDmUwTSGO6yBAS9r7OGVHAbbF5auHKuvcUryyNvCc1a9y3WBT4j8ndpL7kv2FqWiNKH7dNqCNN/QE/SMMHQPSVFX/3V3SBH7UZXou1KpLnbyb2qdh8nhE2osqPjkBn0VJy8FV0Kjf1x2FPhHJiQvCuRsT04mhwz5QHs4id1TUmY+IRL4JT1gzk3GYRLWD4QgaYcusvFa3uGqLM0dOZBV+mV+AclXkk/ICifCuef/j62FxkllNVhNVUTG45f18wehh+e6Yq22RQLz3RQKr33E+fPb+M7AQqfV4tKftJT1GmZ/xhw==" -XPOST -H "CSRFPreventionToken: 57318DC2:et0OAM/BBZzWrC3+EYG2rz3vPM4" -H "Accept: application/json" -d "{'json':{'vmid':'199','ostemplate':'proxnfs:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz','node':'proxa3'}}" -vvv https://proxa3.mydomain.org:8006/api2/json/nodes/proxa3/lxc


> POST /api2/json/nodes/proxa3/lxc HTTP/1.1
> User-Agent: curl/7.35.0
> Host: proxa3.mydomain.org:8006
> Cookie: PVEAuthCookie=PVE:root@pam:57318DC2::mPRd4bxDmUwTSGO6yBAS9r7OGVHAbbF5auHKuvcUryyNvCc1a9y6fc8L0/kcyQ8gPwfxR+5N0nc0IcyeQ+jH3WBT4j8ndpL7kv2FqWiNKH7dNqCNN/QE/SMMHQPSVFX/3V3SBH7UZXou1KpLnbyb2qdh8nhE2osqPjkBn0VJy8FV0Kjf1x2FPhHJiQvCuRsT04mhwz5QHs4id1TUmY+IRL4JT1gzk3GYRLWD4QgaYcusvFa3uGqLM0dOZBV+mV+AclXkk/ICifCuef/j62FxkllNVhNVUTG45f18wehh+e6Yq22RQLz3RQKr33E+fPb+M7AQqfV4tKftJT1GmZ/xhw==
> CSRFPreventionToken: 57318DC2:et0OAM/BBZzWrC3+EYG2rz3vPM4
> Accept: application/json
> Content-Length: 112
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 112 out of 112 bytes
< HTTP/1.1 400 Parameter verification failed.
< Cache-Control: max-age=0
< Connection: close
< Date: Tue, 10 May 2016 08:09:31 GMT
< Pragma: no-cache
* Server pve-api-daemon/3.0 is not blacklisted
< Server: pve-api-daemon/3.0
< Content-Length: 337
< Content-Type: application/json;charset=UTF-8
< Expires: Tue, 10 May 2016 08:09:31 GMT
<
* Closing connection 0
* SSLv3, TLS alert, Client hello (1):
{"errors":{"vmid":"property is missing and it is not optional","{'json':{'vmid':'199','ostemplate':'proxnfs:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz','node':'proxa3'}}":"property is not defined in schema and the schema does not allow additional properties","ostemplate":"property is missing and it is not optional"},"data":null}
 
That's due to the way you're passing the data.
Here's an example of a working call (assuming the csrfprevention token is in the file header and the auth cookie in cookie):
Code:
$ curl -s -D/dev/stderr -k \
    -H "$(<header)" -b "$(<cookie)" \
    -XPOST \
    -d hostname=test3 \
    -d password=12345 \
    -d rootfs=localThin:4 \
    -d ostemplate=iso-templates:vztmpl/alpine-3.2.3-x86_64.tar.gz \
    -d vmid=602 \
    -d 'net0=name%3Deth0,bridge%3Dvmbr0' \
    "https://127.0.0.1:8006/api2/json/nodes/olga/lxc"

I included the network as an example with "=", since you need to url-encode them.
 
Ah, thanks Wofgang,

that did the trick ..... ultimately this helped me to troubleshoot pyproxmox which I needed to get working with lxc