[SOLVED] API request with curl

Yhalti

New Member
Jul 6, 2020
2
0
1
34
Hi, this is my very first message on this forum so excuse me if I do something wrong.

I'm currently trying to change the cloud-init parameter (ipconfig) by using curl.

I've tried several request and the latest was something like this :
Code:
curl -s -k --cookie "PVEAuthCookie=$ticket" -H "CSRFPreventionToken: $csrf" -X Post https://my.proxmox.adress/api2/json/nodes/myNode/qemu/$vmid/config?ipconfig0="ip=$ip,gw=$gate"

I've naturally read the api doc on the subject , but I struggle at understanding how to fill the format which requires the ip and the gw at the same time for this ipconfig parameter. PS: this API request is a part of a bigger project which won't let me use pvesh.

Any help would be appreciated.
 
hi,



ipconfig0="ip=$ip,gw=$gate"

something like this: ipconfig0: ip=192.168.1.50/24,gw=192.168.1.1

maybe you're missing the CIDR notation in the IP?
 
a quick an easy way to find out how to encode an API request is to do the same action in the browser while having the developer tools open, then select the request in the network tab and use the 'copy as curl' option ;)

so in this case, this would be (a bit reduced from what the browser actually generated, since it sets all sorts of headers that are not actually needed)
Code:
curl 'https://$HOST:8006/api2/extjs/nodes/$NODE/qemu/$VMID/config' \
  -X 'PUT' \
  -H 'CSRFPreventionToken: $CSRF_TOKEN' \
  -H 'Cookie: $TICKET_COOKIE' \
  --data-raw 'ipconfig0=ip%3D122.122.122.1%2F24%2Cgw%3D122.122.122.2'

as you can see, that value of the ipconfig0 key needs to be URL-encoded
 
as you can see, that value of the ipconfig0 key needs to be URL-encoded

Thank for the different answers, I didn't think about using the web browser + developper tool.
I managed to make the api request that I wanted.
 

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!