proxmox api error

kennysinkeler

New Member
Oct 1, 2016
6
0
1
27
hello,
i have the following if use de code of the bottom
i have the error
HTTP/1.1 401 No ticket Cache-Control: max-age=0 Connection: close Date: Sat, 01 Oct 2016 15:11:36 GMT Pragma: no-cache Server: pve-api-daemon/3.0 Expires: Sat, 01 Oct 2016 15:11:36 GMT bool(true)

if i use my command line then is it fine.


Code:
class ProxmoxController extends Controller
{
   protected $cookietoken = null;
  

   public function __construct() {
     $ch = curl_init();

     curl_setopt($ch, CURLOPT_URL,"https://proxmox.sinkeler.net:8006/api2/json/access/ticket");
     curl_setopt($ch, CURLOPT_POST, 1);

     curl_setopt($ch, CURLOPT_POSTFIELDS,
       "username=root@pam&password=REMOVED");
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

     $server_output = curl_exec ($ch);

     curl_close ($ch);
     $ticket = json_decode($server_output);
     $this->cookietoken = $ticket->data->ticket;
   }

   public function users()
   {
     $headers = array(
  "Cache-Control: no-cache",
  'Pragma: no-cache',
  );
     $string  = 'PVEAuthCookie:" '.$this->cookietoken.' " ';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL,"https://proxmox.sinkeler.net:8006/api2/json/access/users");
  
     curl_setopt($ch,  CURLOPT_COOKIE, $string );
     curl_setopt($ch, CURLOPT_HEADER, 1);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  
     $server_output = curl_exec ($ch);
     curl_close ($ch);
     var_dump($server_output);

   }
}
 
Last edited by a moderator:
I did not check whether your server is reachable from the public internet, but I removed the password you hard coded into your code snippet. It is not a good idea to post your passwords in public, especially not together with the server domain/URL/IP. I'd advise you to change it nevertheless, since it was public here for almost 2 days..

As to your actual problem: the server says that you did not provide a ticket, so the first step would be to check your authentification code for errors.