[SOLVED] API request with curl

Yhalti

New Member
Jul 6, 2020
2
0
1
30
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.
 

oguz

Proxmox Staff Member
Staff member
Nov 19, 2018
2,042
212
63
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?
 

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
4,301
671
133
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
 

Yhalti

New Member
Jul 6, 2020
2
0
1
30
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 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 your own in 60 seconds.

Buy now!