API - Add user to VM as Administrator

Miguel Alfaiate

New Member
Dec 17, 2017
10
0
1
34
Hello.

I am trying to integrate Proxmox API into a PHP based tool we have, and I have been able to create a virtual machine, start it up and create a user.

I want to add the created user to the created VM as an administrator of that machine.

$fields = array(
'user' => "{$username}@pve",
'role' => "Administrator",
'path' => "/qemu/{$vmID}"
);


$vmCreationURL = $this->proxmoxHost . "access/acl";

$response = $this->makeRequest($vmCreationURL, $fields);


The make request function makes a post request using curl, it's the same function I use to make the request for creating a VM or starting it up, as well as creating a user. It handles token addition to the request and other stuff such as parsing the response.

Just as an example, this is the logic for creating a new user:

$fields = array(
'userid' => "{$username}@pve",
'password' => $password
);


$vmCreationURL = $this->proxmoxHost . "access/users";

$response = $this->makeRequest($vmCreationURL, $fields);

Exactly the same formate, just the endpoint changes.

When I do the request to that acl endpoint, I get the following error:


POST value: user=user26%40pve&role=Administrator&path=%2Fqemu%2F10055

Request sent to https://[MY HOST]/api2/json/access/acl

HTTP code: 501
Response header HTTP/1.1 501 Method 'POST /access/acl' not implemented
Cache-Control: max-age=0
Connection: close
Date: Tue, 19 Mar 2019 17:26:42 GMT
Pragma: no-cache
Server: pve-api-daemon/3.0
Content-Length: 13
Content-Type: application/json;charset=UTF-8
Expires: Tue, 19 Mar 2019 17:26:42 GMT

Response Body {"data":null}


Is this the correct URL to post that information to? Am I using the wrong URL, wrong parameters or what am I missing?

Thank you.
 

Miguel Alfaiate

New Member
Dec 17, 2017
10
0
1
34
I forgot to mention, but I did already try that before.

I tried using both "vms/10055" and "qemu/10055".


Nonetheless, bear in mind that the error seems to point to a different problem, which is the endpoint either not existing or not accepting post requests. Am I using the wrong endpoint?

POST value: user=user26%40pve&role=Administrator&path=%2Fvms%2F10055
Request sent to https://[MY HOST]/api2/json/access/acl
HTTP code: 501
Response header HTTP/1.1 501 Method 'POST /access/acl' not implemented
Cache-Control: max-age=0
Connection: close
Date: Wed, 20 Mar 2019 12:06:06 GMT
Pragma: no-cache
Server: pve-api-daemon/3.0
Content-Length: 13
Content-Type: application/json;charset=UTF-8
Expires: Wed, 20 Mar 2019 12:06:06 GMT


Response Body {"data":null}
Response:
 

Miguel Alfaiate

New Member
Dec 17, 2017
10
0
1
34
Thank you very much!

That API viewer is a life saver!

I have searched for that several times and did not find anything. Have been getting things to work by trial and error, based on some wiki info and such...
 

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!