UrielCh / proxmox-api

TypeScript Api for proxmox
56 stars 15 forks source link

$post and $put request send data as querystrings #10

Closed timcole closed 1 year ago

timcole commented 1 year ago

Mutation requests $post, $put send query strings for data instead of using the body.

Something went wrong Error: post https://{REDACTED}:8006/api2/json/nodes/ceres/qemu/901/clone?full=1&name=26d534a50eb5&newid=105 return Error 400 Parameter verification failed.: {"data":null,"errors":{"newid":"property is missing and it is not optional"}}
    at ProxmoxEngine.doRequest (/app/node_modules/proxmox-api/dist/ProxmoxEngine.js:159:23)
const newid = await ctx.proxmox.cluster.nextid.$get();
const vm = await ctx.proxmox.nodes
  .$(node!)
  .qemu.$(template.vmid)
  .clone.$post({
    full: true,
    name: `${randomBytes(6).toString('hex')}`,
    newid,
  });
UrielCh commented 1 year ago

add a console.log(newid) for me it do not contains a number. ... newid=105 oups it looks ok. I will check that later.

did it work with the previous version?

timcole commented 1 year ago

Just downgraded again and it's broke in 0.2.0 as well 😭

UrielCh commented 1 year ago

in one of my scripts I use this code:

          console.log(`Using template ${template.vmid} (${template.name})`);
          console.log(`build VM: ${id} on ${server.hostname}`);
          const newid = 1000 + id;
          await server.destroyVM(newid)

          // const newid = 1000 + id;
          console.log(`creating VM: ${newid}`);
          await api.nodes
            .$(server.node)
            .qemu.$(template.vmid)
            .clone.$post({ newid, name: `vm-${serverName}-${id}` });

and it used to work.

It may work only with Proxmox 6, Can not with Proxmox 7. I publish a 0.3.2, which may fix this issue, but I can not test it right now.

timcole commented 1 year ago

Maybe Proxmox 6 supported sending query params? We are using Proxmox 7 so can't check but I think that's likely.

Can't test the new update in our same codebase because we swapped out for an own in-house solution yesterday (too many bugs and licensing issues for our liking with this lib) but created a sample script just to test the update for you and seems to be fixed now.

Thanks for the resolution and best of luck on the project!