Posting to the Proxmox 2.0 API - 401 Unauthorized

gutter007

New Member
May 1, 2012
19
0
1
I'm trying to create qemu virtual machine containers using the Proxmox 2.0 API. I'm able
to authenticate the root user, and use the GET command to access data. Hovever, when I
try to post data I get a "401 Unauthorized" error and {data:null}, no matter what I try.

I'm using a ruby application, with the rest client. I tested my rest call with
rest-test.heroku.com and I get the following response:


POST http://rest-test.heroku.com/resource with a 741 byte payload, content type
application/x-www-form-urlencoded {"vmid"=>"216", "name"=>"test_build", "memory"=>"1022",
"cores"=>"2", "bootdisk"=>"iso/CentOS-6.2-x86_64-netinstall.iso", "sockets"=>"2",
"CSRFPreventionToken"=>"5058DF00:fOY2slze+9E6TnKsC8dSZSdItek",
"ide0"=>"local=5,format=raw", "ostype"=>"l26",
"ide2"=>"local:iso/iso/CentOS-6.2-x86_64-netinstall.iso, media=cdrom",
"net0"=>"rtl8139,bridge=vmbr20",
"Cookie"=>"PVEAuthCookie=PVE:root@pam:5058DF00::cesBu4/H4Ub3NAo9+n567/yTMeGTmw/
KvM0kByOWB8Ih1i+uzoxWnibj04fTv0LIEU4P5RdLsDA8Sc+i6HLrdMBpmNSFxNP1QbG3DjWHQ4QTiyaM+
f7ivMR3jU5mGLyHi62XMV9rCbh7COI0Azt8eCdEATuyEJ4QZkNdmHp/
F8PdU6mzmYf4zIFVd20fLlZIsHH8LyahhkUpDDuM6pY74cO4eWdDYJPunE2sODgXzcqlJc/
Xufws2NID66UKhwbspVw3Q8orosYnGkQ0CJPxI+F2lLPVQSA601veShaop/PCACxmBH/
yI9YwhFHmsQD6wRyyVrVHeUuw9nZXq9in1A=="}



What am I doing wrong when making the call? I have the PVEAuthCookie setup identically to
that of the GET responses, and I have added the CSRFPreventionToken to the headers. I
have tried a large number of permutation to no avail.

thanks.
myles.
 
CSRFPreventionToken and PVEAuthCookie seems to contain white space character (which is definitely wrong).
 
It doesn't have whitespace in them. The quote command introduced them somehow
Code:
POST [URL]http://rest-test.heroku.com/resource[/URL] with a 741 byte payload, content type
application/x-www-form-urlencoded {"vmid"=>"216", "name"=>"test_build", "memory"=>"1022",
"cores"=>"2", "bootdisk"=>"iso/CentOS-6.2-x86_64-netinstall.iso", "sockets"=>"2",
"CSRFPreventionToken"=>"5058DF00:fOY2slze+9E6TnKsC8dSZSdItek",
"ide0"=>"local=5,format=raw", "ostype"=>"l26",
"ide2"=>"local:iso/iso/CentOS-6.2-x86_64-netinstall.iso, media=cdrom",
"net0"=>"rtl8139,bridge=vmbr20",
"Cookie"=>"PVEAuthCookie=PVE:root@pam:5058DF00::cesBu4/H4Ub3NAo9+n567/yTMeGTmw/
KvM0kByOWB8Ih1i+uzoxWnibj04fTv0LIEU4P5RdLsDA8Sc+i6HLrdMBpmNSFxNP1QbG3DjWHQ4QTiyaM+
f7ivMR3jU5mGLyHi62XMV9rCbh7COI0Azt8eCdEATuyEJ4QZkNdmHp/
F8PdU6mzmYf4zIFVd20fLlZIsHH8LyahhkUpDDuM6pY74cO4eWdDYJPunE2sODgXzcqlJc/
Xufws2NID66UKhwbspVw3Q8orosYnGkQ0CJPxI+F2lLPVQSA601veShaop/PCACxmBH/
yI9YwhFHmsQD6wRyyVrVHeUuw9nZXq9in1A=="}
 
That's actually an error caused by the quote tag. Let's try it with the code tag:

Code:
POST http://rest-test.heroku.com/resource with a 741 byte payload, content type
application/x-www-form-urlencoded {"vmid"=>"216", "name"=>"test_build", "memory"=>"1022",
"cores"=>"2", "bootdisk"=>"iso/CentOS-6.2-x86_64-netinstall.iso", "sockets"=>"2",
"CSRFPreventionToken"=>"5058DF00:fOY2slze+9E6TnKsC8dSZSdItek",
"ide0"=>"local=5,format=raw", "ostype"=>"l26",
"ide2"=>"local:iso/iso/CentOS-6.2-x86_64-netinstall.iso, media=cdrom",
"net0"=>"rtl8139,bridge=vmbr20",
"Cookie"=>"PVEAuthCookie=PVE:root@pam:5058DF00::cesBu4/H4Ub3NAo9+n567/yTMeGTmw/
KvM0kByOWB8Ih1i+uzoxWnibj04fTv0LIEU4P5RdLsDA8Sc+i6HLrdMBpmNSFxNP1QbG3DjWHQ4QTiyaM+
f7ivMR3jU5mGLyHi62XMV9rCbh7COI0Azt8eCdEATuyEJ4QZkNdmHp/
F8PdU6mzmYf4zIFVd20fLlZIsHH8LyahhkUpDDuM6pY74cO4eWdDYJPunE2sODgXzcqlJc/
Xufws2NID66UKhwbspVw3Q8orosYnGkQ0CJPxI+F2lLPVQSA601veShaop/PCACxmBH/
yI9YwhFHmsQD6wRyyVrVHeUuw9nZXq9in1A=="}